unit testing - Is this design for dependency injection easy to understand? -
I am working on a project with a large current codebase and I have been entrusted with the task of doing some reconsideration. A small part of it does not have too many unit tests in the existing codebase, but at least I like the part that has a complete suite of unit tests with good code coverage.
Because designing in mind with existing codebase unit testing, I have to make some structural changes to support the separation of dependency. I am trying to keep an impact on the existing code as possible, but I have a small discount to make changes in other modules. I have a reaction that I should understand the changes made or if I have made the following changes to the best way to deal with the problem:
-
I have all those non-trivial The interface for the classes is drawn on which my 'coordinator' class depends on.
-
I have modified the coordinator class to reference only the interface for my operation.
-
I could not use the D framework, but I had to inject a large number of dependencies (with additional dependency urgency as part of class dependency), so I Modified the coordinating class of (Domain-Specific Name Simplified):
Public Sealed Class Coordinator {Private IFactory_factory; Public Coordinator (Intimate): This (Ultimate, New Standard Factor) () Public Coordinator (Int Ultimate, IF.T.Free Factory) {_factory = Factory; // Factory used elsewhere elsewhere ...} Public Interface IFactory {IClassA BuildClassA (); Iclasb buildlabsab (string absolute); ICLSC BuildClass (C); } Private Sealed Class Standards: Impact {public Icillas buildlas A () (returning new class); } Public IClassB BuildClassB (String Ultimate) {Return New Class B (Ultimate); } Public IClassC BuildClassC () {returning new class ()); }}}
This allows the injection of a stabbed factory, which can return mechanical dependency for unit testing. My concern is that it also means that any user of this class can supply their factory to change the way the class operates, which is not really intended, this constructor is fully intelligent for unit testing. , But this means that additional extravagance intended to have side effects. I generally do not see this method in other sections which I am used to, so I wonder if I am confused and if there is a better way of getting the necessary separation.
Note: Something strange is happening with code formatting, so I apologize for the bad formatting above. It is not certain why it will not allow me to format correctly.
The proposed design is of a type of strong> manufacturer injectable sometimes Bastard In the case of a greenfield situation, I consider an anti-pattern in bestser injection, but it is a good agreement in a brownfield situation, as you describe it.
You should not really be worried about the underlying expansion of the coordinator class. Correctly done, therefore ideally the injected IFactory should represent the proper domain concept that enables variability. I understand that when you are refactoring with the legacy code, getting on a stroke can be difficult / impossible, but this is the direction in which your code base is running.
In any case, if your colleague can already humiliate extraction of the interface, it is unlikely to interpret the IFactory constructor parameter as an accessibility point. .
Good luck.
Comments
Post a Comment