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,130 | Comments: 45,558

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.


  1. How to waste CPU and kill your disk by scaling 100 million inefficiently - 9 hours from now
  2. RavenDB Conference 2016–Slides - about one day from now

There are posts all the way to Jun 01, 2016


  1. The design of RavenDB 4.0 (14):
    26 May 2016 - The client side
  2. RavenDB 3.5 whirl wind tour (14):
    25 May 2016 - Got anything to declare, ya smuggler?
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats