mercredi 24 décembre 2014

Which design is better? [MainClass] -> [Class] OR [MainClass] -> [MiddleClass] -> [Class]


I have two designs which achieve the same result.



-------Design A


enter image description here MainClass has a List and two methods. The methods create an autonomous object and is added to the list. The reason for the superclass, B and C are similar and I will be adding more subclasses. Furthermore, I can take advantage of polymorphism later on.



-------Design B


enter image description here mainclass has two methods. The method creates a aggregation link with MiddleClass and directly calls Mainclass methods - which returns an autonomous object of class b/c.


Unlikely A, B benefits from a higher degree of (loose)coupling from the MainClass, where the MiddleClass acts handles information from the inheritance hierarchy to the mainclass - And of course, the more subclasses I add, the mainclass will not have any additional links to the hierarchy, instead, it's all dealt with by middleclass.


However, I am not sure if I am just over-engineering the design or if it's a better design. What do you guys think is the better design and why?





Aucun commentaire:

Enregistrer un commentaire