Course contentsShow
← Software Engineering
Lesson 298 of 1,9339. Behavioral Design PatternsFree lesson

The Mediator Pattern: Centralizing Communication

Understand how Mediator reduces coupling by routing interactions between objects through a central coordinator.

The Mediator Pattern: Centralizing Communication

What you'll learn: How the Mediator pattern reduces coupling by routing all interactions between objects through a single central coordinator.

The Problem: Tangled Communication

Imagine a busy airport control tower scenario. Without the tower, every pilot would need to communicate directly with every other pilot—checking positions, coordinating takeoffs, negotiating landing sequences. The complexity explodes as more planes arrive. Each pilot needs to know about every other pilot.

In software, when multiple objects interact directly with each other, they become tightly coupled. Object A calls Object B, which calls Object C, which needs to notify Object A... The web of dependencies becomes difficult to understand, test, and modify.

How Mediator Solves It

The Mediator pattern introduces a central coordinator object. Instead of objects talking directly to each other, they all communicate through the mediator. The mediator knows how to route messages and coordinate interactions.

Like an airport control tower:

  • Pilots (objects) only talk to the tower (mediator)
  • The tower coordinates all communications between planes
  • Pilots don't need to know about each other

Key Benefits

Reduced coupling: Objects don't hold references to each other—only to the mediator. You can change one object's behavior without affecting others.

Centralized control logic: Complex interaction rules live in one place (the mediator), not scattered across many objects.

Easier maintenance: When interaction patterns change, you modify the mediator, not every participating object.

Trade-off

The mediator can become a "god object" if it accumulates too much logic. It needs careful design to avoid becoming overly complex itself.

Key Takeaway: The Mediator pattern reduces coupling by making objects communicate through a central coordinator rather than directly with each other, simplifying complex interaction networks at the cost of centralizing coordination logic.