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

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.

主站蜘蛛池模板: 简阳市| 郑州市| 丹江口市| 中方县| 祥云县| 怀仁县| 浮梁县| 封丘县| 信丰县| 河池市| 察雅县| 云林县| 漾濞| 伊金霍洛旗| 昭通市| 陇西县| 天镇县| 抚远县| 门头沟区| 名山县| 东兴市| 应城市| 江源县| 边坝县| 南昌县| 喀喇| 镇康县| 兴国县| 城步| 浮梁县| 泊头市| 当雄县| 太湖县| 定结县| 苏尼特右旗| 神池县| 贵港市| 洪洞县| 微山县| 白朗县| 平度市|