diff --git a/notes/pics/mediator-after.png b/notes/pics/mediator-after.png new file mode 100644 index 00000000..ef5f90e3 Binary files /dev/null and b/notes/pics/mediator-after.png differ diff --git a/notes/pics/mediator-before.png b/notes/pics/mediator-before.png new file mode 100644 index 00000000..ecbf5534 Binary files /dev/null and b/notes/pics/mediator-before.png differ diff --git a/notes/设计模式 - 中介者.md b/notes/设计模式 - 中介者.md index 4cbd06ca..548f3095 100644 --- a/notes/设计模式 - 中介者.md +++ b/notes/设计模式 - 中介者.md @@ -17,11 +17,11 @@ Alarm(闹钟)、CoffeePot(咖啡壶)、Calendar(日历)、Sprinkler(喷头)是一组相关的对象,在某个对象的事件产生时需要去操作其它对象,形成了下面这种依赖结构: -

+

使用中介者模式可以将复杂的依赖结构变成星形结构: -

+

```java public abstract class Colleague { diff --git a/tools/diagram/src/mediator-after.svg b/tools/diagram/src/mediator-after.svg new file mode 100644 index 00000000..583c5353 --- /dev/null +++ b/tools/diagram/src/mediator-after.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + 中介者:网状依赖变成星形 + + Alarm + + CoffeePot + + Calendar + + Sprinkler + + Mediator + + + + + 每个对象只把事件交给 Mediator,由它决定通知谁,例如闹钟响了就调用咖啡壶、日历和喷头。 + diff --git a/tools/diagram/src/mediator-before.svg b/tools/diagram/src/mediator-before.svg new file mode 100644 index 00000000..a671a0b1 --- /dev/null +++ b/tools/diagram/src/mediator-before.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + 没有中介者:对象之间互相调用 + + Alarm + + CoffeePot + + Calendar + + Sprinkler + + + + + + + 4 个对象之间有 6 条依赖,新增一个对象就要修改其它所有对象。 +