Define an object that centralizes communication between other objects. Many objects communicate in complex ways. You want to reduce direc
Mediator
Overview
Define an object that centralizes communication between other objects.
When to use
- Many objects communicate in complex ways.
- You want to reduce direct dependencies between components.
Java example
TypeScript example
Pros and cons
Pros:
- Reduces coupling between components.
- Centralizes complex interaction logic.
Cons:
- Mediator can become too large.
- Single point of failure.
Common pitfalls
- Packing domain logic into the mediator.
- Using mediator for trivial interactions.