I have question regarding composite pattern.
Is the base class "Component" act like a pointer to point leaf object in "Composite" class?
<strong>Edit:</strong> Let me ask my question in following words. <strong>"What is the relation between Composite and Component class?"</strong>
Here is the uml class diagram of the pattern.
<a href="https://i.stack.imgur.com/SdmLG.gif" rel="nofollow"><img alt="alt text" class="b-lazy" data-src="https://i.stack.imgur.com/SdmLG.gif" data-original="https://i.stack.imgur.com/SdmLG.gif" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>Answer1:
Relation between composite and component:
1) Leaf and Composite usually implement one interface or one abstract class. In your diagram they extend Component. So, the relation on your diagram is <strong>inheritance</strong>.
2) Composite contains instances of Component. Component, as it occasionally can be Composite, can also contain instances of Component. This is called <em>recursive composition</em>. In general, the relation is called <strong>aggregation</strong>.Answer2:
<strong>Component</strong><ul><li>is the abstraction for all components, including composite ones</li> <li>declares the interface for objects in the composition</li> <li>(optional) defines an interface for accessing a component's parent in the recursive structure, and implements it if that's appropriate</li> </ul>
<strong>Leaf</strong><ul><li>represents leaf objects in the composition</li> <li>implements all Component methods</li> </ul>
<strong>Composite</strong><ul><li>represents a composite Component (component having children)</li> <li>implements methods to manipulate children</li> <li>implements all Component methods, generally by delegating them to its children</li> </ul>
<a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">http://en.wikipedia.org/wiki/Composite_pattern</a>Answer3:
All container and containee classes declare an “is a” relationship to the interface(<em>Component</em>).
All container classes declare a one-to-many “has a” relationship to the interface.
More <a href="http://sourcemaking.com/design_patterns/composite" rel="nofollow">here</a>