Card 08/ 08
Recap: Mediator Pattern
Colleagues talk to one coordinator, trading a web of links for one busy class.
Mediator replaces direct references between many objects with one coordinator they all report to.
- Intent. Encapsulate how a set of objects interact, so they do not refer to each other.
- Structure. Colleagues hold the mediator interface; the concrete mediator holds every colleague and their rules.
- The count. n colleagues need n(n-1)/2 links directly, and n through a mediator: 10 against 5 for five.
- Against Facade. A facade is called from outside; a mediator is called by the objects it coordinates.
- Against Observer. An observer listens to one subject; a mediator sits between colleagues that both send and receive.
- The trap. One mediator collecting every rule; keep each to one conversation.
- When not. Two or three objects, or a one-way announcement Observer already covers.
← → move through sections and cards