Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,007 | Comments: 44,761

filter by tags archive

Design patterns in the test of timeMediator

time to read 1 min | 180 words

The mediator pattern defines an object that encapsulates how a set of objects interact. This pattern is considered to be a behavioral pattern due to the way it can alter the program's running behavior.

More about this pattern can be found here.

Like the Façade pattern, I can absolutely see the logic of wanting to use a mediator. It is supposed to make it easier to work with a set of objects, because it hides their interactions.

In practice, almost all known cases are bad ones. In fact, in most systems that I have seen any association of the name to the actual pattern it is supposed to represent is not very associated at all.

The differences between façade and mediator are minute, and you would think the same advice would apply. However, while you can find a lot of usages of facades (or at least things people would call facades), there are very few real world examples of mediator pattern in use. And almost all of them carry the marks that say: “Just read GoF book, @w$0m3!!!”

More posts in "Design patterns in the test of time" series:

  1. (21 Jan 2013) Mediator
  2. (18 Jan 2013) Iterator
  3. (17 Jan 2013) Interpreter
  4. (21 Nov 2012) Command, Redux
  5. (19 Nov 2012) Command
  6. (16 Nov 2012) Chain of responsibility
  7. (15 Nov 2012) Proxy
  8. (14 Nov 2012) Flyweight
  9. (09 Nov 2012) Façade
  10. (07 Nov 2012) Decorator
  11. (05 Nov 2012) Composite
  12. (02 Nov 2012) Bridge
  13. (01 Nov 2012) Adapter
  14. (31 Oct 2012) Singleton
  15. (29 Oct 2012) Prototype
  16. (26 Oct 2012) Factory Method
  17. (25 Oct 2012) Builder
  18. (24 Oct 2012) A modern alternative to Abstract Factory–filtered dependencies
  19. (23 Oct 2012) Abstract Factory


Ricardo Peres

One example of a Mediator that we use everyday is the ASP.NET web forms page: it knows and performs operations in controls that exist inside of it. Don't you agree?


Isn't a service bus, or any kind of messaging system, a mediator? I'd also consider the events and callbacks parts of jQuery an example of the mediator pattern. I've found both to be very useful. I've also written small classes hook two services together so I can test that they're wired together correctly. Isn't that a mediator?


How about: The Messenger class of Mvvm Light? The Event Agreggator implementation of Caliburn? or this implementation in Js? http://thejacklawson.com/Mediator.js/

I think that can be very useful when you need to build loosely coupled components.


I agree with Trystan that a non-distributed message/event bus or a command queue should be considered a mediator.

Judah Gabriel Himango

Yep, the MessageBus/PubSub is a mediator, and it's commonly found in MVVM frameworks to communicate between view models. It's also used in web apps to communicate between components in a page.

I use Knockout.PostBox (https://github.com/rniemeyer/knockout-postbox) to do pub/sub in my web apps. Very slick. Components (e.g. observables) communicate by publishing messages on the mediator object, ko.postbox.

I even use it for application commands. So my Song object can simply call ko.postbox.publish("Play", this) to tell my application to start playing that song. It doesn't care who is listening for that command, thus decoupling the implementation from the usage. Works out nicely.

Ayende Rahien

Guys, I don't consider message passing to be mediator. It is own separate thing.


Ayende, I would like to hear your explanation about what diferentiates Mediator and MessageBus/Event Aggregator.

Ayende Rahien

Euproric, Think about the distinction between Facade & Mediator, or Stategy & State. Those are really subtle distinctions, but they need different names, to express their differences. To call MessageBus a Mediator is the same, except the gap is FAR larger.


What about the mediators in PureMvc framework in ActionScript -It mediates between UI and command -Command in turn interacts with Server via a Proxy

Ayende Rahien

Chandan, I am sorry, but I am not going to even try to comment on something like that. I don't have a clue about ActionScript, far less about a specific framework in ActionScript.

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Speaking (3):
    23 Sep 2015 - Build Stuff 2015 (Lithuania & Ukraine), Nov 18 - 24
  2. Production postmortem (11):
    22 Sep 2015 - The case of the Unicode Poo
  3. Technical observations from my wife (2):
    15 Sep 2015 - Disk speeds
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series



Main feed Feed Stats
Comments feed   Comments Feed Stats