基本概念
Mediator Pattern: Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
实现代码
组件
中介者
测试类
Q & A
What are advantages of using mediator patterns?
- Support centralizing control.
- Reduced complexity: It simplifies the interactions between different components or objects, making the system easier to understand and maintain.
- Promote loose coupling: Objects or components do not communicate directly with each other, but through a mediator. This reduces the dependencies among them, making it easier to change, extend, and re-use individual components.