Structural Pattern
Facade
Provide a unified, simplified interface to a set of interfaces in a subsystem, making it easier to use.
One simple door.
The Facade pattern gives you a single, easy front door to a complicated system. Rather than making callers coordinate many classes, you offer one object with a few high-level methods that do the orchestration behind the scenes.
Example: a HomeTheaterFacade.watchMovie() turns on the projector, dims the lights, powers
the amplifier, and starts the player — the caller just calls one method.
bad.py
# Problem: client must orchestrate a noisy subsystem by hand. encoder = VideoEncoder() encoder.set_codec("h264") encoder.set_bitrate(4000) audio = AudioMixer() audio.normalize(track) uploader = CdnClient() uploader.put(encoder.encode(file), audio.mix()) # Every caller repeats this ritual — and breaks when internals change.
good.py
# Fix: Facade offers one simple method over the subsystem. class VideoFacade: def publish(self, file, track): # Hide encoder / mixer / CDN wiring behind one door. encoder = VideoEncoder() encoder.set_codec("h264") encoder.set_bitrate(4000) audio = AudioMixer().normalize(track) CdnClient().put(encoder.encode(file), audio) # Clients only know publish() — subsystem can be refactored freely. VideoFacade().publish("clip.mp4", "voice.wav")
Decoupling clients from subsystems.
The Facade wraps a subsystem's classes and delegates client requests to the right components. Clients depend only on the facade, reducing coupling to the many moving parts inside.
- Doesn't hide the subsystem — advanced clients can still use subsystem classes directly when needed.
- Reduces learning curve — a small, task-oriented API over a large subsystem.
- Layering — facades often mark the entry point of a subsystem layer.
Boundaries and relations.
- vs Adapter — Facade defines a new, simpler interface over many objects; Adapter makes an existing object match a specific expected interface.
- Law of Demeter — facades help clients avoid reaching deep into subsystem internals.
- Risk: god object — a facade can grow into a bloated do-everything class; keep it focused, or provide several role-specific facades.
- Often a Singleton — a subsystem usually needs only one facade instance.