SOLID & Design Patterns Interview Question #62

What is the difference between Facade and Mediator?

Advanced Patterns, CQRS & Domain-Driven Design Fundamentals Mid-Level Intermediate

Quick Interview Answer

Facade provides a simpler interface for clients to access a complex subsystem. Mediator coordinates communication among peer components so those components do not need to reference each other directly.

Detailed Explanation

Facade provides a simpler interface for clients to access a complex subsystem. Mediator coordinates communication among peer components so those components do not need to reference each other directly.

Facade is primarily about simplifying a boundary for external callers. Mediator is primarily about reducing many-to-many communication among collaborating objects.

Code Example

Facade:
Controller -> CheckoutFacade -> subsystem

Mediator:
ComponentA -> Mediator <- ComponentB
                    ^
                    |
                ComponentC