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: Go program and captured output
package main
import "fmt"
type Heater struct{}
func (Heater) On() { fmt.Println("heater: warming to 21 degrees") }
type Lights struct{}
func (Lights) On() { fmt.Println("lights: on at 40%") }
type CoffeeMachine struct{}
func (CoffeeMachine) Brew() { fmt.Println("coffee: brewing espresso") }
// The facade: one simple door to the whole subsystem.
type House struct {
heater Heater
lights Lights
coffee CoffeeMachine
}
func (h House) StartDay() {
h.heater.On()
h.lights.On()
h.coffee.Brew()
}
func main() {
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 type 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 types; a facade that hides too much pushes people to bypass it.