I have a base class called “Entity” which has a static method called “construct” that returns an Entity instance. I have several different subclasses of this class (for demonstration assume we have “Fruit” and “Vegetable” as subclasses).
I would like to be able to do something along the following lines:
Entity a = someFunction(Fruit, textfile)
someFunction would then pass textfile to Fruit.construct and return the Entity generated.
Is there a simple way to do this?
Use a factory pattern instead.
Pass the text file to the factory method that will use it to return the proper concrete instance of
Entity