Mediator Design Pattern
Problem
Partitioning a system can increase reusability. However, if as the number of classes increases then number of interconnections also increase that reduces the reusability. This is because the classes more and more rely on the existence of the others. How can we favor weak coupling and increase reusability?
Solution
A mediator provides and interface, and a level of indirection between dependant classes. A mediator, for instance, can sit between a list box, and a text entry field. When the list box changes, it tells the mediator, who then gets the text from the list box and passes it to the text entry box. So, the text entry box does not need to know about the list box, and does not have any interdependency with it. This is implemented by having both the text entry and list boxes derive off of a colleague base class which has a method Changed() which tells the mediator whenever the box changes. Then the mediator determines what needs to be done to maintain the system functioning properly.
Consequences
Changing how a system of objects interacts requires only subclassing the mediator, and the colleague classes remain unchanged. As well, the mediator provides the one place that controls the object, and determines how they communicate. A mediator also reduces the number of interface methods, as context specific methods are not required.