Mediator Design Pattern


Authors: Chetan Giridhar and Rahul Verma

As per wikipedia:

“ The mediator pattern provides a unified interface to a set of interfaces in a subsystem. This pattern is considered to be a behavioral pattern due to the way it can alter the program’s running behavior..”

Typically, mediator pattern is used in cases where many classes start communicating amongst each other to produce result. When the software starts getting developed, more user requests get added and in turn more functionality need to be coded. This results in increased interaction with in the existing classes and in addition of new classes to address new functionality. With the increasing complexity of the system, interaction between classes becomes tedious to handle and maintaining the code becomes difficult.

Mediator pattern comes in as a solution to this problem by allowing loose-coupling between the classes, also called as Colleagues in the Mediator Design Pattern. The idea is that there would be one Mediator class that is aware of the functionality of all the classes in the system. The classes are aware of their functionality and interact with the Mediator class. Whenever there is a need of interaction between the classes, a class sends information to the Mediator and it is the responsibility of the Mediator to pass this information to the required class. Thus the complexity occurring because of interaction between the classes gets reduced.

Read More…


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s