(I'll assume it really does make sense to accept the date as a string, and that "ric" means something in your domain. It's certainly a general enough issue.)
You can't do this as the two constructors have the same signature, but a nice workaround is to use static factory methods:
private static RateInstrument(string ric, string tenor, string date)
{
...
}
public static RateInstrument FromRicAndTenor(string ric, string tenor)
{
return new RateInstrument(ric, tenor, null);
}
public static RateInstrument FromRicAndDate(string ric, string date)
{
return new RateInstrument(ric, null, date);
}
Advantages of static construction methods:
- Doesn't always have to return a new instance (it could apply pooling, etc)
- Could return null if that was really useful
- Can do useful work before and after construction more easily than a constructor can
Disadvantages:
- Looks odd when you're used to calling "new"
- Inheritance can become trickier (you'd have to at least make the constructor protected, for non-nested derived types)
(Both of these suffer from lack of injectability, compared with instance methods on an actual factory type, of course.)