SRP: A factory should not belong into the class it's a factory for - especially not when possibly also creating couple other classes
Coupling: Making the factory method a non virtual class function will have the same static binding as calling the constructor. Knowing the classes to create in the base class factory method also couples the base class to their child classes.
Testability: Hiding classes in the implementation section seem clever first but it avoids testing these classes in isolation - for testing they should not be retrieved through the factory because that involves code in the test that is not subject of the test.
SRP: A factory should not belong into the class it's a factory for - especially not when possibly also creating couple other classes
ReplyDeleteCoupling: Making the factory method a non virtual class function will have the same static binding as calling the constructor. Knowing the classes to create in the base class factory method also couples the base class to their child classes.
Testability: Hiding classes in the implementation section seem clever first but it avoids testing these classes in isolation - for testing they should not be retrieved through the factory because that involves code in the test that is not subject of the test.
SRP
ReplyDeletebesides it we have KISS, YAGNI and Occam's razor