Intent

Define an object that encapsulates details and other objects interact with such object. The relationships are loosely decoupled.

Where to use & benefits

Structure


Participants

Mediator  (ICommandMediator)
defines an interface for communicating with Colleague objects

ConcreteMediator  (CommandContainer)
implements cooperative behavior by coordinating Colleague objects and knows and maintains its colleagues

Colleague classes  (CommandColleague)
each Colleague class knows its Mediator object and communicates with its mediator to communicate with other objects

Example

In the demonstration application, the shape (Rectangle, Trinagle, Circle) objects communicates with CommandContainer class to issues the commands (encapsulated as Command object) to draw the shape, by extending the CommandColleague classs which holds the information about the mediator object. Here, only one way communication is implemented, since the other way communication is not necessary.

Class Diagram


Source Code Links