Applied Design Patterns with Java

Behavioral :: Mediator (273) {C ch 20}


Example - Java :: Patterns\Behavioral\Mediator

Pattern Concept: to allow the simplification and streamlining of the intercommunication among a large group of classes. The Mediator pattern is useful when a group of classes are so tightly coupled that their interconnections are a tangled web, reducing extensibility and increasing maintenance. A Mediator class promotes loose coupling by providing a common means of mediating among the classes: instead of knowing how to communicate with each other, they only need to know how to communciate with the Mediator. Only the Mediator class has detailed information about the other classes, and when one class needs to communicate a change to another class, the Mediator forwards the request.

This illustration shows such a tangled set of interconnections:

The use of a Mediator streamlines and simplifies these communication interfaces:


Example - UML : MedDemo
Here is Cooper's Class Diagram for the application using this logic, followed by the Rose equivalent:





The example Java program is called 'MedDemo'.

The UML diagram is above, and the list of Java files is below:

Issues and consequences of the Mediator pattern include:

Catalog Behavioral Prev Next