Facade
Provides a simplified, unified interface to a complex subsystem, hiding its internal complexity from clients.
errorWhat Problem Does the Facade Pattern Solve?
Complex subsystems with many interdependent classes force clients to understand low-level internals, initialization order, and inter-object wiring. This tight coupling makes clients fragile when the subsystem evolves and raises the barrier to using the subsystem correctly.
check_circleHow the Facade Pattern Works
Create a Facade class that exposes a small, cohesive API for the most common use cases. The facade internally orchestrates the subsystem’s classes in the correct sequence. Clients use the facade; advanced users can still bypass it to access the subsystem directly when needed.
Facade Pattern Architecture
Rendering diagram...
Implementation by Language
Facade Pattern in the Real World
“A hotel concierge is a facade for the city’s complex infrastructure. Instead of you directly calling a taxi company, booking a restaurant, and arranging a museum ticket separately, the concierge handles all of it through a single conversation. The underlying services still exist in their full complexity—you just don’t deal with them directly.”
Frequently Asked Questions
helpDoes Facade violate the Single Responsibility Principle?
Not necessarily. A Facade's single responsibility is to provide a simplified interface to a subsystem. It delegates all actual work to the underlying classes. If the Facade grows too large, it may indicate the subsystem itself needs restructuring, or you may need multiple focused Facades.
helpCan I have multiple Facades for the same subsystem?
Yes, and it is a common practice. Different clients may need different simplified views of the same subsystem. An AdminFacade and a CustomerFacade might expose different operations on the same underlying classes, each tailored to its audience.