Structural PatternsFacade PatternMedium⏱️ ~2 min

Facade Pattern - Structure and Participants

Core Structure
The Facade Pattern involves three main participants organized in a hierarchical relationship where the facade sits between clients and subsystem classes.
Facade
- subsystemA: SubsystemA
- subsystemB: SubsystemB
+ operation(): void
↓ delegates to
SubsystemA
+ methodA1(): void
+ methodA2(): void
SubsystemB
+ methodB1(): void
+ methodB2(): void
SubsystemC
+ methodC1(): void
Participant Responsibilities
Facade
Knows which subsystem classes are responsible for a request. Delegates client requests to appropriate subsystem objects. Contains references to subsystem components (composition relationship ◆).
Subsystem Classes
Implement subsystem functionality. Handle work assigned by the Facade object. Have no knowledge of the facade (no back-reference).
Client
Uses the facade instead of calling subsystem classes directly. May still access subsystem classes if complex operations are needed.
Typical Implementation Flow
1. Client calls facade.operation()
2. Facade initializes subsystem objects if needed
3. Facade calls subsystemA.methodA1()
4. Facade calls subsystemB.methodB2()
5. Facade calls subsystemC.methodC1()
6. Facade aggregates results and returns to client
Interview Tip: Emphasize that the facade uses composition (◆), not inheritance. It holds references to subsystem objects and delegates work, but does not extend their behavior.
💡 Key Takeaways
Facade contains references to subsystem components via composition
Subsystem classes have no knowledge of the facade
Client can bypass facade for direct subsystem access if needed
Facade coordinates multiple subsystem calls in a single operation
📌 Examples
1<code>HomeTheaterFacade</code> contains <code>DVDPlayer</code>, <code>Projector</code>, <code>Amplifier</code> objects
2<code>OrderFacade</code> delegates to <code>InventoryService</code>, <code>PaymentService</code>, <code>NotificationService</code>
← Back to Facade Pattern Overview
Facade Pattern - Structure and Participants | Facade Pattern - System Overflow