中介者模式
用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显示地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。
Mediator Pattern
Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from refering to each other explicitly, and it lets you vary their interaction independently.
类图
模式的结构与使用
中介者模式的结构中包括四种角色。
+ 中介者(Mediator):中介者使一个接口,该接口定义了用于同事(Colleague)对象之间进行通信的方法。
+ 具体中介者(Concrete Mediator):具体中介者是实现中介者接口的类。具体中介者需要包含所有具体同事(Concrete Colleague)的引用,并通过实现中介者接口中的方