17.行为型:中介者设计模式
目录介绍
- 01.中介模式的原理
- 02.中介模式举例
- 03.中介模式案例代码
- 04.中介VS观察者
- 05.重点知识回顾
- 06.知识问题思考一下
01.中介模式的原理
- 中介模式的英文翻译是 Mediator Design Pattern。在 GoF 中的《设计模式》一书中,它是这样定义的:
- Mediator pattern defines a separate (mediator) object that encapsulates the interaction between a set of objects and the objects delegate their interaction to a mediator object instead of interacting with each other directly.
- 翻译成中文就是:
- 中介模式定义了一个单独的(中介)对象,来封装一组对象之间的交互。将这组对象之间的交互委派给与中介对象交互,来避免对象之间的直接交互。
- 如何给代码解耦
- 其中一个方法就是引入中间层。
- 中介模式的设计思想
- 实际上,中介模式的设计思