diff --git a/notes/pics/dp-mediator.png b/notes/pics/dp-mediator.png new file mode 100644 index 00000000..f203f62f Binary files /dev/null and b/notes/pics/dp-mediator.png differ diff --git a/notes/设计模式 - 中介者.md b/notes/设计模式 - 中介者.md index 548f3095..d92fb95e 100644 --- a/notes/设计模式 - 中介者.md +++ b/notes/设计模式 - 中介者.md @@ -1,20 +1,15 @@ ## 5. 中介者(Mediator) -### Intent - +### 意图 集中相关对象之间复杂的沟通和控制方式。 -### Class Diagram - - - +### 类图 - Mediator:中介者,定义一个接口用于与各同事(Colleague)对象通信。 - Colleague:同事,相关对象 -

- -### Implementation +

+### 实现 Alarm(闹钟)、CoffeePot(咖啡壶)、Calendar(日历)、Sprinkler(喷头)是一组相关的对象,在某个对象的事件产生时需要去操作其它对象,形成了下面这种依赖结构:

@@ -154,17 +149,21 @@ public class Client { } ``` -```java +```text doAlarm() doCoffeePot() doCalender() doSprinkler() ``` -### JDK - +### JDK 中的应用 - All scheduleXXX() methods of [java.util.Timer](http://docs.oracle.com/javase/8/docs/api/java/util/Timer.html) - [java.util.concurrent.Executor#execute()](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html#execute-java.lang.Runnable-) - submit() and invokeXXX() methods of [java.util.concurrent.ExecutorService](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html) - scheduleXXX() methods of [java.util.concurrent.ScheduledExecutorService](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html) - [java.lang.reflect.Method#invoke()](http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#invoke-java.lang.Object-java.lang.Object...-) + +## 参考资料 + +- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007. +- Gamma E. 设计模式: 可复用面向对象软件的基础 [M]. 机械工业出版社, 2007.