Carl Danley

The Mediator Pattern

The American Heritage dictionary defines the word mediator as "one that mediates, especially one that reconciles differences between disputants." In this manner, the mediator pattern usually implements a single object that becomes a shared resource through all of the different pieces of an application. It's a higher-level version of pub/sub in that it's commonly used to communicate across the different features of an application in contrast to being used within one feature to communicate with all of the individual pieces of that same feature.

"Understanding the similarities and differences between an event aggregator and mediator is important for semantic reasons."
- Derick Bailey

This article is part of a series called JavaScript Design Patterns.

Advantages

Disadvantages

Example

Additional Resources

http://lostechies.com/derickbailey/2013/03/18/event-aggregator-andorvs-mediator-a-tale-of-two-patterns/
http://www.dofactory.com/javascript-mediator-pattern.aspx
http://addyosmani.com/resources/essentialjsdesignpatterns/book/#mediatorpatternjavascript

Other Common JS Patterns

The Module Pattern
The Revealing Module Pattern
The Singleton Pattern
The Observer Pattern
The Mediator Pattern
The Prototype Pattern
The Facade Pattern
The Factory Pattern