I have a situation where I have a composite class that describes an entire object, called Ship. The Ship can have many configurations, where I may want to add a Torpedo object, a Sea Mine object, etc. However I don't want to add these objects to the Ship, just some minimal reference to the type of object.
One way to do it would be to have a string array containing the names of the items, and then use a switch statement to return the corresponding object, but that seems like a clunky solution.
I was wondering if there's a neat pattern for this, where you can refer to a class type for building a composite object, without instantiating it yet.
Aucun commentaire:
Enregistrer un commentaire