title: Composite Pattern in Java : Practical Implementation
body: <p>I was reading the book "Design Patterns" and going over Composite Pattern. Please go through this <a href="http://paginas.fe.up.pt/~aaguiar/as/gof/hires/pat4cfso.htm" rel="nofollow noreferrer" title="link">link</a> to get the context of the problem. The following class diagram is given in the book :-
  <a href="https://i.stack.imgur.com/6Ruao.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6Ruao.gif" alt="enter image description here"></a></p>
  
  <p>My question is about the practice of implementing this pattern in Java.</p>
  
  <ol>
  <li>How will <code>Graphic</code> be defined -- as an <strong>Interface</strong> or an <strong>abstract class</strong>?</li>
  <li><code>Graphic</code> declares method like <code>Add(Graphic)</code>, <code>Remove(Graphic)</code> and <code>GetChild(int)</code>. The classes that are implementing (or extending) <code>Graphic</code> will have to give their implementation to these methods. But classes like <code>Line</code>, <code>Rectangle</code> and <code>Text</code> do not need these methods. So while implementing <code>Graphic</code> interface or extending <code>Graphic</code> abstract class, what will these classes do with respect to these methods. Can they have blank or empty implementations for these methods?</li>
  </ol>