Skip to main content
Design Patterns 80 XP · 8 min

Mediator: Centralized Communication

Restrict direct communication between objects — force them to collaborate through a mediator to reduce chaotic many-to-many dependencies.

Showing
Ad (728×90)

Why this matters

Think of an airport. Planes don't talk to each other directly — they all communicate through the control tower. Without the tower, every plane would need to know about every other plane. With it, each plane only needs one connection. Mediator applies the same hub-and-spoke model to your objects: instead of N objects each holding references to N-1 others (O(N²) connections), every object holds one reference to the mediator (O(N) connections).

The problem

Bad

The solution

Good

Real-world appearances

UI frameworks use Mediator constantly. A form with many fields that enable/disable each other shouldn't have fields wired to each other — a form controller (mediator) handles it. Redux and Vuex are Mediators for application state. Event buses (Node.js EventEmitter, browser CustomEvent) are mediators. Chat servers, message brokers (RabbitMQ, Kafka) — all variations of the same idea.

Key takeaway

When too many objects communicate directly with too many others, Mediator extracts that complexity into one place — a hub that everyone talks to, reducing O(N²) connections to O(N).

Done with this lesson?

Mark it complete to earn XP and track your progress.