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 API and its right order. startDay() hides the choreography behind one call.
One simple door
The caller writes one line; the facade knows the order (heat first, coffee last). If the routine changes, only the facade changes.
Output: PHP script
<?php
class Heater {
public function on(): void {
echo "heater: warming to 21 degrees\n";
}
}
class Lights {
public function on(): void {
echo "lights: on at 40%\n";
}
}
class CoffeeMachine {
public function brew(): void {
echo "coffee: brewing espresso\n";
}
}
// The facade: one simple door to the whole subsystem.
class House {
public function __construct(
private Heater $heater = new Heater(),
private Lights $lights = new Lights(),
private CoffeeMachine $coffee = new CoffeeMachine(),
) {}
public function 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.