标签:
迭代器模式(Iterator), Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. (它提供一各方法访问一个窗口对象中各个元素,而又不需暴露该对象的内部细节。)
通用类图:
角色:
1. Iterator抽象迭代器:负责定义访问和遍历元素的接口。在Java中,只迭代器为interface,其中定义了三个方法,hasNext(), next(), remove().
2. ConcreteIterator具体迭代器:实现迭代器接口,完成元素的遍历。持有容器的引用以完成遍历。
3. Aggregate抽象容器: 负责创建具体迭代器角色的接口,必须提供类似createIterator()这样的方法。在Java中,一般是iterator()方法。
4. ConcreteAggregate具体容器。
标签:
原文地址:http://www.cnblogs.com/wayhow/p/5326211.html