diff --git a/notes/pics/dp-visitor.png b/notes/pics/dp-visitor.png new file mode 100644 index 00000000..afce94c1 Binary files /dev/null and b/notes/pics/dp-visitor.png differ diff --git a/notes/设计模式 - 访问者.md b/notes/设计模式 - 访问者.md index 94fe917d..104bd102 100644 --- a/notes/设计模式 - 访问者.md +++ b/notes/设计模式 - 访问者.md @@ -1,19 +1,16 @@ ## 访问者(Visitor) -### Intent - +### 意图 为一个对象结构(比如组合结构)增加新能力。 -### Class Diagram - +### 类图 - Visitor:访问者,为每一个 ConcreteElement 声明一个 visit 操作 - ConcreteVisitor:具体访问者,存储遍历过程中的累计结果 - ObjectStructure:对象结构,可以是组合结构,或者是一个集合。 -

- -### Implementation +

+### 实现 ```java public interface Element { void accept(Visitor visitor); @@ -182,7 +179,7 @@ public class Client { } ``` -```html +```text customer1 order1 item1 @@ -200,7 +197,11 @@ Number of orders: 4 Number of items: 6 ``` -### JDK - +### JDK 中的应用 - javax.lang.model.element.Element and javax.lang.model.element.ElementVisitor - javax.lang.model.type.TypeMirror and javax.lang.model.type.TypeVisitor + +## 参考资料 + +- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007. +- Gamma E. 设计模式: 可复用面向对象软件的基础 [M]. 机械工业出版社, 2007.