I have a base class B with multiple constructors. I have a derived class D which has some additional fields to be set in its constructor(s), implemented as shown below.
B(args1) {...}
B(args2) {...}
...
B(argsN) {...}
D(args1, additional) : B(args1) {...}
D(args2, additional) : B(args2) {...}
...
D(argsN, additional) : B(argsN) {...}
Problem is, every time a new B constructor is added with new args I have to make a new D constructor. Any way around this?
D(argsN=null)? I would think about do you always need a new constructor..Bit might be, let's say,BArgs, for D -DArgs : Bargs. Then you would passDArgsto B constructor.DArgswould extendBArgswith youradditionalparameter.Dis inherited fromB? MaybeDcan simply create and hold an instance ofB? Normally you don't choose inheritance in such scenario. And you understand, what addingB(argsX)doesn't require fromDto implementD(argsX, additional)?