I searched a lot of places, but I did not find a good answer for my problem:
I have an enumeration, for example:
public enum Window { CLASSIC, MODERN }
and I need to separate the behavior of my application according to the enum value, for example:
switch (myWindow.getType()) { case CLASSIC: new ClassicWindow(...); case MODERN: new ModernWindow(...); }
I know what you think: just put this in enum and basta, however this is not the only class that depends on my listing! And I canโt write as many methods of creating objects as I have objects!
Simply put, what can I do in this situation? A friend of mine told me to get rid of the enumeration and use the derived classes every time, but in the end I would have to create as many instances as there are subclasses for all my tests!
In short, I'm stuck.
Do you know what is best for this? Thanks
source share