I am currently modifying a class that has 9 different constructors. Now overall, I believe that this class has been designed very poorly ... so I'm wondering if this is a bad design for being a lot of constructors for a class.
A problem arose because I recently tried two constructors this class to reactor and redesign this class to a square (some manager in the code given below) so that this unit test Qualified and not dependent on all its methods. However, because the other constructors were easily hiding from the beginning of the class by looking at the hundred lines, when I added my constructor
now what is happening is the code that calls these other consultants Some manager depends on the class which has already been interlitted because it was stable ... the result is a reference exception exception.
So my question is how can I fix this issue? Trying to reduce the number of constructors? All existing constructors take an Isoom manager parameter?
Of course, one classroom does not need 9 constructors! ... oh, and there are 6000 lines in this file to leave it up!
Here is a censored representation of the constructors which I am referring to:
Public MyManager (): This (new SomeManager ()) {} // I Public MyManager added (IomeManager someManager) // This one I added {this.SomeManager = someManager; } Public MyManager (int id): The public MyManager (some class someClass): this (some class, DateTime.Now) (SomeClass! = Null) MyHelper = New MyHelper (some other class, some date, "some absolute"); } Public MyManager (SomeOtherClass someOtherClass): This (some other class, datetime.now) {} Public MyManager (some other class some other class, date time someDate) {myHelper = New MyHelper (some other class, some date, "some absolute "); } Public MyManager (Other Classes Still Other Class): This (So far, second class, Datetime. Now) {} Public MyManager (yet another class, second class, date time a few days) {myHelper = New MyHelper (now Till the second class, some days, "some absolute"); }
Update:
Thanks to everyone for your responses ... they are very good!
Just thought I would give an update on what I've finished.
To address the issue of the Null Reference exception, I have modified an additional constructor to take an ISomeManager.
Right now my hand is tied when it comes to allow this special class to be re-applied, then I will flag it for once again to design it in my list of classes When I get some free time At the moment, I am happy that I am able to refact some manager classes ... this was very big and awesome as my manager class.
When I start designing MyManzer again, I'm looking for a way to remove the functionality in two or three separate sections ... or to make sure SRP's adherence is done.
Finally, I have not come to the conclusion that the maximum number of constructs for any of the classes, but I believe that in this special frequency, I have two or three sections with two or three constructors
One class should do only one thing and do the same if it has many Constructor, then this is a story telling point that many things Su is.
Using several controllers to emphasize the exact formation of objects in different situations, but looks like 9 very much. I suspect that there is an interface and some implementations of the interface that can be pulled out. Each of them has a possibility from one to a few constructors, each related to their specificity.
Comments
Post a Comment