The ninth pattern --------Iterator and Composite Pattern
2009-08-23 15:45
232 查看
OO原则:
一个类应该只有一个引起变化的原因
解释:类的每个责任都有改变的潜在区域。超过一个责任,意味着超过一个改变的区域。所以我们要尽量让每个类保持单一责任。
OO模式:
迭代器模式:提供一种方法顺序访问一个聚合对象中的各个元素,而又暴露其内部的表示。
组合模式:允许你将对象组合成树形结构来表现“整体/部分”层次结构。组合能让客户以抑制的方式处理个别对象以及对象组合。
组合的方式能让我们用树形方式创建对象的结构,树里面包含了组合以及个别的对象。
一般是树形结构或者是曾次结构用到组合模式
要点:
1) 迭代器允许访问聚合的元素,而不需要暴露它的内部结构。
2) 迭代器将遍历聚合的工作封装进一个对象中。
3) 当使用迭代器的时候,我们一来聚合提供遍历。
4) 迭代器提供了一个通用的接口,让我们遍历聚合的项,当我们编码使用聚合的项时,就可以使用多态机制。
5) 我们应该努力让一个类只分配一个责任。
6) 组合模式提供一个结构,可同时包容个别对象和组合对象。
7) 组合模式允许客户对个别对象以及组合对象一视同仁。
8) 组合结构内的任意对象称为组件,组件可以是组合也可以是叶节点。
一个类应该只有一个引起变化的原因
解释:类的每个责任都有改变的潜在区域。超过一个责任,意味着超过一个改变的区域。所以我们要尽量让每个类保持单一责任。
OO模式:
迭代器模式:提供一种方法顺序访问一个聚合对象中的各个元素,而又暴露其内部的表示。
组合模式:允许你将对象组合成树形结构来表现“整体/部分”层次结构。组合能让客户以抑制的方式处理个别对象以及对象组合。
组合的方式能让我们用树形方式创建对象的结构,树里面包含了组合以及个别的对象。
一般是树形结构或者是曾次结构用到组合模式
要点:
1) 迭代器允许访问聚合的元素,而不需要暴露它的内部结构。
2) 迭代器将遍历聚合的工作封装进一个对象中。
3) 当使用迭代器的时候,我们一来聚合提供遍历。
4) 迭代器提供了一个通用的接口,让我们遍历聚合的项,当我们编码使用聚合的项时,就可以使用多态机制。
5) 我们应该努力让一个类只分配一个责任。
6) 组合模式提供一个结构,可同时包容个别对象和组合对象。
7) 组合模式允许客户对个别对象以及组合对象一视同仁。
8) 组合结构内的任意对象称为组件,组件可以是组合也可以是叶节点。
相关文章推荐
- Design Pattern学习笔记之迭代器模式和复合模式(the Iterator and Composite Pattern)
- 《Head First设计模式》 读书笔记10 迭代器与组合模式 The Iterator and Composite Patterns
- Iterator and Composite Pattern
- Double-checked locking and the Singleton pattern--双重检查加锁失效原因剖析
- Inversion of Control Containers and the Dependency Injection pattern ---- Martin Fowler
- The servlets named [xxx] and [com.web.xxx] are both mapped to the url-pattern
- Head First Design Pattern - 2 - A Subject and Observer spar over the right way to get state information to the Observer
- The seventh pattern --------The Adapter Pattern and Facade Pattern
- Inversion of Control Containers and the Dependency Injection pattern
- Complexities with NHibernate, DataTransferObjects and the Assembler Pattern(Ben Scott's Blog)
- pattern and design - proxy patter the basic
- Inversion of Control Containers and the Dependency Injection pattern
- Martin Fowler的Inversion of Control Containers and the Dependency Injection pattern(中文版)
- IoC容器和 Dependency Injection模式 Inversion of Control Containers and the Dependency Injection pattern
- What is the difference between Enumeration and Iterator ?
- SCSF - Part 5 Dependency Injection and the Composite Application Block
- Double-checked locking and the Singleton pattern
- The servlets named [X] and [Y] are both mapped to the url-pattern [/Z] which is not permitted
- Double-checked locking and the Singleton pattern
- Inversion of Control Containers and the Dependency Injection pattern