Evaluating design of a system with Mediator

Evaluating the design of a system with mediator

To increase the usability and flexibility of this system, lets introduce a level of indirection within the system. This level of indirection is called as the Mediator.

Once the mediator is introduced to resolve the complexity of interaction the system looks like in the following figure

Figure- Figure

Lets again reevaluate this system wrt its pros and cons.

I hope the figure looks very clean as compared to the first design, hence maintainability and manageability of the system improves by a great factor.

What happens to flexibility?

As we can see, this level of indirection increases the flexibility by a great factor. In fact the property of this design is Ö irrespective of the type of change (structural or behavioral) that takes place there will be minimum impact on the system. If any of the structural components gets added/removed or modified .. worst the impact will be limited to the mediator similarly any behavioral change will be either limited to the component or the mediator.

What are the limitations of this design?

As mediator is a level of indirection and since every communication between the structural components will now be mediated through the mediator, the performance of this design will be low as compared to the first design.

Second, mediator can be a single point of failure within the system and if the mediator fails, system can come to a knee jerk halt. Hence availability also suffers in this design.As we know that a mediator encapsulates the entire logic of interaction between the components , if the mediator mediates more than 10-12 colleagues, the mediator itself can become a huge monolithic piece of code which will be very difficult to understand , maintain and debug .

So we need to find out a way to address these limitations as well. The solution is introduce hierarchy of mediators .The figure below describes one of the solutions to address these limitations to a certain extent.

Figure- Figure

If we evaluate this new design with hierarchy of mediators, we can see there is no single point of failure with the system, the system can partially fail but it is difficult for the entire system to fail completely.

None of the individual mediators is mediating more than 10 colleagues and hence they donít land up becoming complex.

The flip side of this design is , because we have added hierarchy of indirections, the performance still reduces in certain communications.

In general we can whenever there is a system wherein there are large number of structural components who are supposed to interact with each other directly, resolve the n*n interaction using the mediator design pattern.

This design pattern is also called as the Broker Architectural Pattern or the Hub and Spoke Architectural style.

 
Hemant Jha
Founder - VPlanSolutions
Researcher, Trainer

www.VPlanSolutions.co.in