Skip to content

Design Patterns

Facade

The facade itself adds O(1) overhead (a constant, small amount). It just forwards the call to the real work underneath.

The idea, in plain English

A facade works like a hotel front desk. Behind it are housekeeping, room service, and billing — lots of separate departments. But you just tell the front desk what you need, and it handles the rest. In code, a facade is one simple object that hides a bunch of complicated parts behind an easy front door.

How it works

  1. 1You start with several smaller classes or steps that need to happen together, in the right order.
  2. 2You build one 'facade' object that knows how to call all of them correctly.
  3. 3Your code just talks to the facade's simple method, instead of juggling every part itself.

When you'd use it

Use this when a task needs several parts working together — like turning on lights, a screen, and music for movie night. You want one simple entry point instead of exposing every piece.

Common beginner mistakes

  • Don't make the facade so 'smart' that it becomes a second complicated system instead of a simple front door.
  • Don't hide things so well that advanced users can't reach the underlying parts when they need to.

Try it — edit and run

Click the code to edit · press ⌘/Ctrl+↵ to run

Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.

Expected output — hit Run to try it
Lights on, Screen down, Music playing

Not sure this is the right topic? See the learning paths → or where this leads →