samedi 17 juin 2017

Composite Pattern in Java : Practical Implementation

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 :- enter image description here

My question is about the practice of implementing this pattern in Java.

  1. How will Graphic be defined -- as an Interface or an abstract class?
  2. Graphic declares method like Add(Graphic), Remove(Graphic) and GetChild(int). The classes that are implementing (or extending) Graphic will have to give their implementation to these methods. But classes like Line, Rectangle and Text do not need these methods. So while implementing Graphic interface or extending Graphic abstract 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