What It Is
The Facade pattern puts one simple door in front of a complicated subsystem. Behind the door, several parts cooperate in the right order; in front of it, the caller makes one call.
The subsystem stays fully available for those who need the details — the facade is a convenience, not a wall.
Example: One Call Starts the Day
Heater, lights, coffee machine — three parts, each with its own method and its right order. startDay() hides the choreography behind one call.
One simple door
The caller writes one line, new House().startDay(); the facade knows the order (heat first, coffee last). If the routine changes, only the facade changes.
Output: TypeScript file and captured output
class Heater {
on(): void {
console.log("heater: warming to 21 degrees")
}
}
class Lights {
on(): void {
console.log("lights: on at 40%")
}
}
class CoffeeMachine {
brew(): void {
console.log("coffee: brewing espresso")
}
}
// The facade: one simple door to the whole subsystem.
class House {
private heater = new Heater()
private lights = new Lights()
private coffee = new CoffeeMachine()
startDay(): void {
this.heater.on()
this.lights.on()
this.coffee.brew()
}
}
new House().startDay()
When to Use It
Use it when callers keep repeating the same multi-step dance with a subsystem, or when you want to expose a small, stable surface over a messy or changing one.
Skip it when the "subsystem" is one class with three methods. A facade over something already simple only adds distance.
Pros and Cons
Pros: callers get one simple call; the right order lives in exactly one place; the subsystem can change behind a stable front.
Cons: facades tend to grow into do-everything classes; a facade that hides too much pushes people to bypass it.