您的位置:首页 > 其它

设计模式总结之Iterator Pattern(迭代器模式)

2016-08-11 00:52 627 查看

目录

设计模式分类

创建型设计模式:
Singleton Pattern(单例模式)   

Prototype Pattern(原型模式)
Factory Method Pattern(工厂方法模式)   

Abstract Factory Pattern(抽象工厂模式)
Builder Pattern(建造者模式)
结构型设计模式:
Adapter Pattern(适配器模式)   

Bridge Pattern(桥接模式)
Composite Pattern(组合模式)
Decorator Pattern(装饰者模式)
Façade Pattern(外观模式)
Flyweight Pattern(享元模式)
Proxy Pattern(代理模式)   

行为型设计模式:
Chain of Responsibility Pattern(职责链模式)
Command Pattern(命令模式)
Interpreter Pattern(解释器模式)   

Iterator Pattern(迭代器模式)
Mediator Pattern(中介者模式)
Memento Pattern(备忘录模式)
Observer Pattern(观察者模式)
State Pattern(状态模式)
Strategy Pattern(策略模式)
Template Method Pattern(模板方法模式)
Visitor Pattern(访问者模式)

Iterator Pattern(迭代器模式)

意图

提供一种方法顺序访问一个聚合对象中各个元素, 而又不需暴露该对象的内部表示。

适用性

1. 访问一个聚合对象的内容而无需暴露它的内部表示。

2. 支持对聚合对象的多种遍历。

3. 为遍历不同的聚合结构提供一个统一的接口(即, 支持多态迭代)。

结构



参与者:

* Iterator(迭代器)

迭代器定义访问和遍历元素的接口。

* ConcreteIterator (具体迭代器)

具体迭代器实现迭代器接口。

对该聚合遍历时跟踪当前位置。

* Aggregate (聚合)

聚合定义创建相应迭代器对象的接口。

* ConcreteAggregate (具体聚合)

具体聚合实现创建相应迭代器的接口,该操作返回ConcreteIterator的一个适当的实例。

例子

编程语言级别已经提供,如:数组、集合、foreach循环。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息