I have an abstract Command class. Every Command class created from a certain class, Fetcher, needs to be endowed with certain properties. Normally this looks like a factory pattern – Fetcher creates a CommandFactory that will prepare the Command when creating it. However there are about a dozen derived classes and I don’t see how to do this without having a different concrete factory for each concrete class, or a different method createConcrete1Command that will have to be extended each time a new Command class is created. Is there any strategy for this?
I have an abstract Command class. Every Command class created from a certain class,
Share
The solution I’ve found to this situation is as follows:
Constructor:
All derived classes will of course taken a
Parametersas an argument, howeverParameterscan be extended as necessary with no need to touch the constructor of any derived class.