Mediator Design Pattern: Sometimes we need a mechanism to facilitate the interaction between objects in a manner in that objects are not aware of the existence of other objects. In other words Mediator helps in achieving loose coupling between various objects by keeping objects from referring to each other explicitly, and it makes their interaction independent.
There are some point which we need to keep in mind while choosing this design pattern.
- Mediator pattern helps to achieve loose coupling.
- You should know if there is a coupling between the components, in you code
- Once you identified the coupling between the components, you can think of using this design pattern.
I will explain it with example how you can decouple your various components from each other with help of a Mediator. Mediator provides us the freedom to do modification in any component without touching other components.