复合图案 [英] Composite Pattern

查看:262
本文介绍了复合图案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对复合模式有疑问。



基类组件是否像复合类中指向叶对象的指针?



编辑:
让我用下面的话来问我的问题。
Composite和Component类之间的关系是什么?



这是模式的uml类图。 p>

解决方案

复合和组件:



1)叶和复合通常实现一个接口或一个抽象类。在图中,它们扩展了Component。所以,图上的关系是继承



2)Composite包含Component的实例。组件,因为它偶尔可以是Composite,还可以包含Component的实例。这称为递归组合。一般而言,关系称为聚合


I have question regarding composite pattern.

Is 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.

这篇关于复合图案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆