Home > Uncategorized > Mediator Pattern

Mediator Pattern

Mediator Pattern

Problem: You have four or five inter-dependent classes which interact between each other to achieve functionality. Due to the interdependency the coupling in the system becomes more.

Now I couldn’t figure a good example, so please bear with a structural one. In this case Object1 knows about Object2, Object3 and Object5. Object2 knows about Object1, Object3 and Object5 and so on. A lot of objects know each other. How do we reduce the coupling between the objects?

 

Solution:

The mediator pattern comes to the rescue. The interaction diagram for the mediator case is as follows,

The GoF class structure diagram is

In the mediator case the individual objects called the colleagues refer the mediator and know only the mediator. Thus the coupling between the objects is reduced.

Categories: Uncategorized
  1. No comments yet.
  1. November 19, 2010 at 11:00 pm

Leave a comment