next up previous contents
Next: Adapter Up: Patterns Used Previous: Command

Mediator

The mediator pattern encapsulates how a set of objects interact [7]. Rather then keeping track of its own dependents, each widget notifies the mediator whenever it changes. The mediator then determines how this will affect any of the other components of the interface. The pattern allows widgets to be more flexible and reusable. All of the code specific to a particular interface is encapsulated within a concrete mediator class.

The interface mediator abstraction:

class InterfaceMediator {
 
  CreateInteface();
  ToolChanged(pjrWidget *theWidget) 
  ...
}

When a widget changes:

this->mediator->ToolChanged(this);

  figure191
Figure 6.4: Partial diagram of mediator. Concrete mediator has handles to platform specific tools (graphical representation of widgets) for platform specific operations.

The interface mediator instantiates all the widgets in the interface. It keeps handles to the specific graphical widgets used so that platform specific operations can be done to the widgets. Outside of the interface mediator, all references to widgets are done through the abstract pjrWidget interface. Any of the ugly details of initializing and maintaining the interface are hidden within the mediator.

Even though a concrete mediator has to be made for each new interface setup, each mediator conforms to the abstract mediator interface, allowing other classes to be independent of any particular mediator.



Paul John Rajlich
Mon May 4 16:53:57 CDT 1998