Skip to main content

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.

Prompt
Write a PHP script with the Facade pattern: Heater, Lights and CoffeeMachine classes each printing their action, and a House facade whose startDay method runs them in the right order. Start the day with a single call.
Output: PHP script

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.