I have a class with an overloaded constructor (C #). It can be initialized in several ways, and some parameters are optional, so the result is an intricate group of constructors
new Object(StrA, StrB, ObjA)
new Object(StrA, StgB, ObjB, StrC)
new Object(StrA, StrB, ObjA, StrD)
new Object(StrA, StrB, ObjB, StrC, StrD)
new Object(StrA, StrB, StrE, ObjA)
new Object(StrA, StrB, StrE, ObjB)
new Object(StrA, StrB, StrE, ObjA, StrC)
new Object(StrA, StrB, StrE, ObjB, StrC, StrD)
I see two ways to improve the situation a) create a structure for storing optional parameters
new Config(StrA, StrB, StrD, StrE)
new Object(Config, ObjA)
new Object(Config, ObjB, StrC)
b) set additional parameters as properties
A = new Object(ObjA)
A.StrA = some;
A.StrB = some;
A.StrD = some;
A.StrE = some;
What is the best way?
And such code refactoring is necessary - the previous supporting code says that "when using intellisense, the complexity of the constructor does not matter - you can always check tips and choose the right one"