I have a question regarding composite pattern.
Does the base class "Component" act like a pointer to point leaf object in "Composite" class?
Edit: Let me ask my question in following words. "What is the relation between Composite and Component class?"
Here is the uml class diagram of the pattern.
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 inheritance .
2) Composite contains instances of Component. Component, as it occasionally can be Composite, can also contain instances of Component. This is called recursive composition . In general, the relation is called aggregation .
Component
Leaf
Composite
All container and containee classes declare an “is a” relationship to the interface( Component ).
All container classes declare a one-to-many “has a” relationship to the interface.
More here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.