Facade
Beginner · 11 min read · Low-Level Design, Structural Patterns
A simple front door to a complex subsystem.
The idea in plain words
A task needs several classes called in the right order. A Facade is one simple class with one simple method that does all those calls for you. Callers use the facade; they don't need to know the steps.
The problem
Placing an order touches many components: inventory reservation, pricing, coupon validation, payment, shipment creation and notification. A controller that orchestrates all of them directly knows every class, every call order and every failure mode:
The solution
A facade offers a small set of high-level operations and does the orchestration internally.
Where you've seen it
Pitfalls
Pros and cons
Comparisons
Facade over a third-party SDK
One of the most valuable facades wraps a vendor SDK you do not control. The SDK's awkward API, its error codes and its types stay inside one class; the rest of your code uses a small interface with your own types. Switching vendors, or testing without the network, then touches one class.
Testing with facades
What interviewers probe
When your design has a facade (often the top-level service in a machine-coding round), expect questions about failure handling (what is compensated if step 4 of 6 fails?), idempotency (what if the client retries placeOrder after a timeout?) and transaction boundaries (which steps must succeed or fail together?).
Interview questions
- What's the difference between a Facade and a Mediator?
- How do you stop a facade from becoming a god class?
- Should a facade be an interface or a concrete class?
Further reading
Key takeaways
- A facade is a simple front door to a complex subsystem: few high-level methods, orchestration inside.
- It doesn't add functionality and doesn't prevent direct subsystem access.
- Keep facades thin and use-case focused; return your own types.
- Service layers, JdbcTemplate, SLF4J and API gateways are facades.
- Wrap third-party SDKs in a facade with your own interface and types (an anti-corruption layer); it makes testing and switching vendors cheap.