vendredi 16 août 2019

Is this code improvable by using any design pattern?

I have the following class hierarchy and would like to know if a design pattern is suitable for this use case.

Class Hierarchy

Short Explanation:

  • The top layer are all pure virtual interfaces. IAnimal is the main interface (the user will get a pointer of this type when creating a new animal).
  • If the user wants to use Property A, he can call the getPropertyAInterface() method of IAnimal. Same for property B. Therefore I dont have one big confusing interface, but several small interfaces with logically related functions.
  • The concrete animals create their specific properties in their constructors (hardcoded).
  • In the future, new animals and new properties will be added

Is it possible to use a design pattern for this? If so, which one? I have read a bit about the decorator and the builder pattern but Iam not sure about it.

Greetings

Aucun commentaire:

Enregistrer un commentaire