How does the Facade pattern differ from Mediator?
Answer
Both Facade and Mediator hide complexity behind a simpler interface, but their roles differ. A Facade provides a simplified one-way interface to a complex subsystem — the subsystem classes are unaware of the facade's existence, and the facade does not coordinate between subsystem classes; it simply delegates. A Mediator actively coordinates two-way communication between multiple colleague objects — all colleagues know the mediator and send messages through it. The facade is a traffic simplifier for client code; the mediator is a traffic controller that orchestrates peer-to-peer communication. In a chat app, a facade wraps the complex networking layer; a mediator manages the communication between users.
Previous
What is the difference between Bridge and Adapter?
Next
What are the internals of the Iterator pattern?
More Design Patterns (Gang of Four) Questions
View all →- Intermediate What is the Template Method design pattern?
- Intermediate What is the Visitor design pattern?
- Intermediate What is the difference between Factory Method and Abstract Factory?
- Intermediate When should you NOT use design patterns?
- Intermediate How are the Gang of Four patterns categorized?