diff --git a/notes/pics/dp-iterator.png b/notes/pics/dp-iterator.png new file mode 100644 index 00000000..6ff07af7 Binary files /dev/null and b/notes/pics/dp-iterator.png differ diff --git a/notes/设计模式 - 迭代器.md b/notes/设计模式 - 迭代器.md index d911fb62..13b2fdf3 100644 --- a/notes/设计模式 - 迭代器.md +++ b/notes/设计模式 - 迭代器.md @@ -1,19 +1,16 @@ ## 迭代器(Iterator) -### Intent - +### 意图 提供一种顺序访问聚合对象元素的方法,并且不暴露聚合对象的内部表示。 -### Class Diagram - +### 类图 - Aggregate 是聚合类,其中 createIterator() 方法可以产生一个 Iterator; - Iterator 主要定义了 hasNext() 和 next() 方法; - Client 组合了 Aggregate,为了迭代遍历 Aggregate,也需要组合 Iterator。 -
image-20191130164425351

- -### Implementation +

+### 实现 ```java public interface Aggregate { Iterator createIterator(); @@ -83,7 +80,11 @@ public class Client { } ``` -### JDK - +### JDK 中的应用 - [java.util.Iterator](http://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html) - [java.util.Enumeration](http://docs.oracle.com/javase/8/docs/api/java/util/Enumeration.html) + +## 参考资料 + +- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007. +- Gamma E. 设计模式: 可复用面向对象软件的基础 [M]. 机械工业出版社, 2007.