官术网_书友最值得收藏!

Explaining Iterator

Imagine that we want a way to access elements of an aggregate object sequentially without exposing its internal structure. The Iterator pattern does just that.

The Iterator pattern is responsible for sequentially accessing the aggregate object and defining an interface to access the elements without exposing the internal structure. This interface doesn't put a new element on the aggregate object, but simply reads elements to it. In the following diagram, you can see the structure of an Iterator and how it is designed:

In the preceding diagram, we can see the Aggregate and Iterator interfaces with their concrete subclasses. The client is the class that uses the Iterator to access elements of Aggregate.

This pattern is used on Java collections such as list, deque, and set. Understanding this pattern will help you to understand Java collections.

主站蜘蛛池模板: 锦州市| 七台河市| 华坪县| 冕宁县| 巴林左旗| 纳雍县| 梓潼县| 安吉县| 翁牛特旗| 长治市| 渭南市| 峨边| 南城县| 东海县| 资源县| 雷山县| 广东省| 岳阳县| 盐山县| 长兴县| 清徐县| 随州市| 肇州县| 鄂托克旗| 垫江县| 上蔡县| 晴隆县| 旺苍县| 丰城市| 阿尔山市| 锡林浩特市| 库伦旗| 新和县| 巴楚县| 福安市| 扶沟县| 泰安市| 宜昌市| 崇阳县| 海晏县| 南宫市|