Application of Mediator

Applications of Mediator

Figure- Figure

Look into the previous figure, does this figure resembles something in this real world?

Does it resembles the design/structure of the internet?

Think about it , if in your office every other computer was connected to every other computer , how will your office look like? And more importantly if a new employee joins, then I hope each and every employee will get affected.

Is it a good design? So how is this solved? The answer is by introducing a hierarchy of mediators at different level of granularity.

Similarly, what can we think about your public telecommunication network?

If in our locality every other telephone was connected to every other telephone by a separate telecommunication cable, how will our locality look like? And more importantly if a new neighbor comes in or moves out all the houses in the locality will get affected.

This resolved again by using mediators wherein all the telephones in a particular locality communicates via the local exchanges(mediators) which in turn are connected to the regional exchanges which in turn are connected to the national exchanges which in turn are connected to the international exchanges.

Similarly, what can we think about the road network of your city/town?

If in your city every locality was connected to every other locality by a separate road, how will your city look like? And if a new locality comes into your city , how many new roads need to be build to facilitate vehicular transportation.

Similarly , what can we think about the railways network of our country?

If every other station was connected to every other station by a separate rail link , how will your country look like and if a new station comes up, how many new rail links need to be build to facilitate passenger movement.

I feel I have given enough examples for a person to understand “Whenever there is a system wherein there are large numbers of structural components who are supposed to interact with each other directly, in this situation there is only one pattern that can used to manage the complexity of a system … and that is the mediator design pattern.”

There are numerous examples of this pattern in this real world and a complex system cannot be designed effectively without using this pattern. This is the reason , this pattern is used along with the controller in most of the systems.

Many a times I come across participants who say that “Can I make my controller act as a mediator or a mediator act as a controller?” The answer is NO.

Can we think as to what is the technical difference between the Controller and the Mediator?

Let us understand , “A controller is a controller because it is Unidirectional” while “Mediator is a mediator because it is Bi Directional” hence it is technically not possible to make a single component play both the roles at the same time.

For example , In project as a system, Project Managers are the controllers while the Project lead/ Module leads/ Group leads are the mediators of the system. When we say that a project lead is a mediator , his job is only to mediate communication between a group of engineers/developers , HIS JOB IS NOT TO CONTROL, THE CONTROL STILL LIES WITH THE PROJECT MANAGER AND THE PROJECT MANAGER CONTROLS EACH OF THE DEVELOPERS WORKING IN THAT PROJECT.

Like conventional systems, software systems can be highly complex as well wherein there can be a large number of structural components/ subsystems wanting to interact with each other, hence mediators are extensively used within software system and to design complex software systems.

Middlewares very often use mediator design pattern as the job of any middleware is to facilitate interactions between multiple systems.

We know systems can communicate either synchronously or asynchronously hence mediators are primarily classified into two types viz Synchronous Mediators and Asynchronous Mediators.

Synchronous Mediator – Synchronous mediator is a mediator which mediates synchronous calls between systems.

Asynchronous Mediator – Asynchronous mediator is a mediator which mediates asynchronous calls (messages) between systems.

ORBs [Object request brokers] of CORBA is an excellent example of synchronous mediators, while Message Brokers are an example of asynchronous mediators.

Online portals like Job Portals, Travel Portals , Matrimonial Portals, Social Networking sites are all example of online mediators [Read patterns in business for more about online mediators].

As discussed before, mediator is the fundamental backbone of any middleware . Infact any middleware is basically designed using the mediator, adapter, decorator and sometime the proxy design patterns.

Hemant Jha
Founder - VPlanSolutions
Researcher, Trainer