I was reading the book "Design Patterns" and going over Composite Pattern. Please go through this link to get the context of the problem. The following class diagram is given in the book :-
My question is about the practice of implementing this pattern in Java.
- How will
Graphicbe defined -- as an Interface or an abstract class? Graphicdeclares method likeAdd(Graphic),Remove(Graphic)andGetChild(int). The classes that are implementing (or extending)Graphicwill have to give their implementation to these methods. But classes likeLine,RectangleandTextdo not need these methods. So while implementingGraphicinterface or extendingGraphicabstract class, what will these classes do with respect to these methods. Can they have blank or empty implementations for these methods?
Aucun commentaire:
Enregistrer un commentaire