mercredi 24 décembre 2014

Which design is better? [Mainclass] - [Subclass] OR [Mainclass] - [HelperClass] - [Subclass]


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 The mainclass has two methods. The method creates an autonomous object of class MiddleClass and directly calls the method addClassB(var) - which returns an autonomous object of class B.


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.


What do you guys think is the better design and why?


THanks!





Aucun commentaire:

Enregistrer un commentaire