码迷,mamicode.com
首页 > 其他好文 > 详细

迭代器模式 (Iterator)

时间:2016-03-27 18:04:44      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

迭代器模式(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具体容器。

 

迭代器模式 (Iterator)

标签:

原文地址:http://www.cnblogs.com/wayhow/p/5326211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!