I have an
abstract class A which declares an abstract method
doStuff. Currently there are many classes that inherit from
A and implement
The class' instances are initialized at run-time via
AFactory based on user input.
Originally all the classes had the same single parameter (the user input). But now I have an additional parameter that only a new class that inherits
So breaking it down I though of the following logic:
The interpreter class that generates instances based on user input(using
AFactoryof course) was not aware of this extra parameter.
- Trying to push it into the class interpreter class would be really awkward because then I would have to know when to pass it to the factory which defeats the whole purpose of having a factory in the first place.
- Sending it blindly into the Factory hoping it might do something with it seems quite ugly as well.
My current solution: Meanwhile I've decided to refactor
AParamscan hold what ever parameters needed and
doStuffcan ignore then if they're not interested in them. This also seems a bit awkward to me , and remids me of sending structs in WIN32API that can hold a lot of ugly useless parameters and I'm not fond of it.
Is there a more elegant way to approach this problem ? Or some design pattern that I've overlooked and solves this?
- We're using Java 1.7
- The class' names are silly in order to emphasize the theoretical design issue they do have normal indicative, meaningful names in reality :)
- I did search quite a lot but having figured out that it's quite hard to search the web for specific abstract theoretical issues (as opposed to why is
Exceptionin this code) I've decided to ask anyway so I'm sorry if this is a duplicate.
- Clarification: I need to pass a subclass-specific argument to the