Sunday, January 31, 2021

Mediator

 




Normally, when we have different objects that need to work together, we'll create references from one object to the other, and the next one, and another one.  While in essence there's nothing wrong with this, it creates tight links between them, decreasing the ability to test them in isolation later on, since we'll have a hard time separating them. Using a mediator, we're introducing an intermediate, an object itself that encapsulates how objects will interact with each other. Our original objects know the mediator, and when one object needs to say something to another object, it just says this to the mediator, which will inform the interested other objects. No tight links anymore, our original objects just know the mediator.


Advantages of Using a Mediator 

  • Avoid hard references from one object to the next
  • Help with communication from/to Core project objects
  • Changes can be handled easily 
  • Easy to test the object


No comments:

Post a Comment