可以查看英文原文:http://www.dofactory.com/Patterns/PatternIterator.aspx
一、迭代器模式:Iterator Pattern
Define:Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
定义:提供一种方式可以连续的访问几何对象的所有元素而无须关注内在的描述方式。
二、UML图

- Iterator (AbstractIterator)
- 定义一个访问和操作元素的接口
- ConcreteIterator (Iterator)
- 实现迭代器的接口
- keeps track of the current position in the traversal of the aggregate.
- Aggregate (AbstractCollection)
- 定义一个接口用于创建一个迭代器对象
- ConcreteAggregate (Collection)
- 实现迭代器创建的接口并且返回一个合适的ConcreteIterator实例对象
三、迭代器模式实例代码
四、一个使用迭代器模式的例子
该例子借助迭代器模式实现以下操作:迭代访问items的元素并且跳过每个迭代过程中items中指定的数字。
本文介绍了迭代器模式,一种设计模式,它提供了一种顺序访问聚合对象成员而不暴露其底层表示的方式。通过示例代码展示了如何在C#中实现迭代器模式,包括创建迭代器接口、具体迭代器类以及如何在实际应用中使用迭代器。
1059

被折叠的 条评论
为什么被折叠?



