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

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.

主站蜘蛛池模板: 灵宝市| 太原市| 乌兰察布市| 丹阳市| 绥棱县| 阿尔山市| 洛宁县| 大竹县| 尼勒克县| 元朗区| 台州市| 莲花县| 舟山市| 长治县| 加查县| 台前县| 广东省| 泰兴市| 永宁县| 泗水县| 合川市| 金阳县| 舒兰市| 麟游县| 崇义县| 汉阴县| 兴宁市| 涞源县| 新乐市| 浙江省| 仙桃市| 宝兴县| 九龙坡区| 屏山县| 电白县| 汉源县| 博爱县| 西峡县| 荔浦县| 桓台县| 铅山县|