Structural

Facade

Facade hides a tangle of interacting classes behind one clean entry point, so client code issues a single high-level call instead of orchestrating the subsystem itself.

Complexity
Popularity

Problem

Suppose your app lets users watch a movie at the press of a button. Behind the scenes, that means dimming the lights, powering on the projector and switching it to widescreen mode, powering on the amplifier and setting its volume, and powering on the DVD player before telling it to play - five objects, each with its own methods, called in a specific order that the client code has to get exactly right.

If that setup logic lives directly in the client, every place that wants to watch a movie duplicates the same multi-step sequence - and stopping a movie needs its own mirrored sequence to power everything down in the right order. Miss a step or get the order wrong, and the amplifier blasts at full volume into a bright room, or the DVD player tries to play before the projector is even on.

Solution

Introduce one class - the facade - that sits in front of the subsystem and exposes only the operations clients actually need, such as `exportVideo(format)`. Internally, the facade owns the job of creating subsystem objects, wiring their dependencies, and calling them in the correct order.

Clients no longer see the codec manager, bitrate reader, or mixer at all - they see one method call. Direct access to the subsystem still exists for cases that need fine-grained control; the facade is an added convenience layer, not a wall.

When to Use

  • Your code only needs a handful of operations from a large, intricate library or subsystem, and you'd rather not learn or expose its full surface.
  • You want a clear seam between architectural layers, with each layer talking to the next only through a defined entry point.
  • You're integrating a third-party framework and want to keep its API from leaking into scattered parts of your application.

Real-World Examples

  • **jQuery** - collapses inconsistent, verbose cross-browser DOM APIs into a handful of chainable calls like `$(el).hide()`, hiding browser-specific quirks entirely.
  • **Django's `Model.objects`** - a facade over SQL connection handling, query building, and row-to-object mapping, letting `User.objects.filter(...)` stand in for dozens of lower-level steps.
  • **Stripe's SDK `charge()` call** - hides HTTP request construction, authentication headers, retries, and error mapping behind a single method for the merchant's application.