I have an interface Fruit
with two implementations Apple
and Banana
. I want to create a Fruit
instance. The choice whether the concrete implementation should be an Apple
or a Banana
should be made by the user. I did not yet design the user interface, so there is no restriction how this choice is made by the user.
I know there are the following options:
- usage of the abstract factory pattern
- usage of reflection to create an instance from a given class name
- usage of reflection to create an instance from a given class object
What are the pros and cons of these options?
Please note that while there are several similar questions that discuss the one or the other approach, I did not find a single comparison.
Here is a list of related questions:
Aucun commentaire:
Enregistrer un commentaire