The Mediator Pattern

Problem

The dependencies between classes within a package can become tangled. For example, if a package contains N classes and if each class depends on every other class, that leads to N! dependencies that must be maintained.

Solution

A mediator is like a virtual post office. If class A wants to send a message to class B, it posts the message to the mediator which either forwards the message to B or places the message in B's message queue where it can be retrieved if and when B needs it.

Structure

Behavior

Discussion

Brokers and dispatchers are mediators.