[英]Composite Pattern
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?"
“Composite 和 Component 类是什么关系?”
Here is the uml class diagram of the pattern.这是模式的 uml 类图。
Relation between composite and component:复合和组件的关系:
1) Leaf and Composite usually implement one interface or one abstract class. 1) Leaf 和 Composite 通常实现一个接口或一个抽象类。 In your diagram they extend Component.
在您的图中,它们扩展了 Component。 So, the relation on your diagram is inheritance .
所以,你的图表上的关系是继承。
2) Composite contains instances of Component. 2) Composite 包含 Component 的实例。 Component, as it occasionally can be Composite, can also contain instances of Component.
Component,因为它有时可以是 Composite,也可以包含 Component 的实例。 This is called recursive composition .
这称为递归组合。 In general, the relation is called aggregation .
通常,该关系称为聚合。
Component成分
Leaf叶子
Composite合成的
http://en.wikipedia.org/wiki/Composite_pattern http://en.wikipedia.org/wiki/Composite_pattern
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.