25.2 组合模式.pdf
《25.2 组合模式.pdf》由会员分享,可在线阅读,更多相关《25.2 组合模式.pdf(14页珍藏版)》请在文库网上搜索。
1、软件体系结构Beijing Jiaotong UniversityZhenyan Ji结构型模式-组合模式组合模式目的将对象组织成树结构以表示“部分整体”的层次结构 。组合模式让client程序以统一的方式对待单个对象和组合对象 。组合模式组合模式参与者Client使用Component接口操作层次结构中的对象。Component是Leaf节点和Composite节点的抽象,它定义了组合中对象必须实现的接口。ClientComponent组合模式Leaf是没有子节 点的对象,其实现由组件接口声明的服务。Leaf组合模式CompositeComposite存储子组件,实现Component接口定
2、义的方法。除了实现Component接口定义的方法。此外,Composite提供添加、删除以及获得组件Component的方法。例子例子public class Employee String name;float salary;Vector subordinates;/-public Employee(String _name, float _salary) name = _name;salary = _salary;subordinates = new Vector(); 例子public float getSalary() return salary;public String getN
3、ame() return name; public void add(Employee e) subordinates.addElement(e);例子public void remove(Employee e) subordinates.removeElement(e); /get a list of employees of a given supervisorpublic Enumeration elements() return subordinates.elements(); 例子:通用接口通用接口/returns a sum of salaries for the employee
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 25.2 组合模式 组合 模式