advanced
Mediator
Centralize collaboration rules between components when direct peer-to-peer dependencies create tangled coordination.
Mediator centralizes how components collaborate so peers do not reference each other directly—chat rooms, form wizards, air traffic control metaphors, UI controllers. It reduces tangled dependencies at the cost of a coordination hub that must stay understandable.
On interviews: compare Mediator with Observer and Event Bus. Explain when a mediator becomes a god object and how to split it.
Common pitfalls: mediators containing business rules that belong in domain layer; synchronous mediators blocking UI; untestable mega-mediators.
Checklist:
- Components talk only through mediator interface.
- Mediator routes messages, not arbitrary logic dumps.
- Split mediators by bounded interaction area.
- Tests simulate component messages in isolation.