What is the difference between facade and mediator design pattern. I want understand which design pattern to choose between these two in which scenario. I was going through
The Facade pattern key notes:
Related post:
What is Facade Design Pattern?
Mediator pattern key notes ( dzone article) :
Mediator pattern is useful when the communication logic between objects is complex, we can have a central point of communication that takes care of communication logic.
We should not use mediator pattern just to achieve lose-coupling because if the number of mediators will grow, then it will become hard to maintain them
Structure:
The Mediator
defines the interface for communication between Colleague
objects.
The ConcreteMediator
implements the Mediator
interface and coordinates communication between Colleague
objects.
It is aware of all the Colleagues
and their purpose with regards to inter communication.The ConcreteColleague
communicates with other colleagues through the mediator
.
Regarding your query:
Your first example represents Facade
pattern. ShapeMaker
is entry point to complex system, which consists of various Shape
sub-systems.
Your second example does not represent Mediator
pattern in true sense. The interactions have been hard-coded. You have to define interfaces and program to those interfaces. Refer to above dzone
article for better understanding of Mediator
example.