mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-29 15:13:44 +00:00
Update 设计模式 - 迭代器.md
小节标题改为中文,重新绘制类图,补充参考资料。
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
+10
-9
@@ -1,19 +1,16 @@
|
||||
## 迭代器(Iterator)
|
||||
|
||||
### Intent
|
||||
|
||||
### 意图
|
||||
提供一种顺序访问聚合对象元素的方法,并且不暴露聚合对象的内部表示。
|
||||
|
||||
### Class Diagram
|
||||
|
||||
### 类图
|
||||
- Aggregate 是聚合类,其中 createIterator() 方法可以产生一个 Iterator;
|
||||
- Iterator 主要定义了 hasNext() 和 next() 方法;
|
||||
- Client 组合了 Aggregate,为了迭代遍历 Aggregate,也需要组合 Iterator。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/image-20201102012333804.png" alt="image-20191130164425351" style="zoom: 67%;" /> </div><br>
|
||||
|
||||
### Implementation
|
||||
<div align="center"> <img src="pics/dp-iterator.png" width="760px"/> </div><br>
|
||||
|
||||
### 实现
|
||||
```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.
|
||||
|
||||
Reference in New Issue
Block a user