Facade Pattern
Put one small, plain interface in front of a subsystem of many classes so that most callers never need to learn the parts.
Overview
The problem it solves A subsystem grows into a dozen classes that must be called in the right order with the right arguments. Every caller learns that order, repeats it, and breaks when it changes. A facade is one class with a few high-level methods that do the coordination. Callers ask for the outcome they want; the facade knows the steps.
The pattern is a structural pattern from the Gang of Four book (Gamma, Helm, Johnson and Vlissides, *Design Patterns*, 1994). The facade adds no new capability. It makes what exists easier to reach and lets the subsystem change behind it.
Interview questions
- What is the difference between a Facade and an Adapter?
- Should callers still be allowed to use the subsystem classes directly?
- When does a Facade become an anti-pattern, and how do you fix it?
- Should a facade translate the exceptions its subsystem throws?
- How do you test code that uses a facade, and the facade itself?
Sign up free to read the full topic
More Low-Level Design topics
Start free on Cariara · Coding problems · System design studio