OO Programming in Java

Class 9 Material


Mediator Design Pattern

We already use it.

Generally when we use GUI components we don't let them talk to one another directly. The OOxxxxx classes (OOCanvas for example) maintain a reference to its parent View (a Mediator) so that it can help orchestrate events which requre other widgets (Colleagues).

The widget Hashtable reduces the complexity of inter-widget communication but still creates a network of interrelated objects. This is fine when the number of objects is small. As the number of interconnected objects grows the complexity of making changes increases. If one widget is removed, other widgets may be affected.

For large numbers of objects the Mediator is better since there is only one place to look when modifications are required.


When do I use the Mediator?

When sets of objects relate to one another in complex ways.

Design Pattern Mediator Example


Our Standard Mediator Example