Early previewThis guide is in development. Items tagged verify are still being checked against official docs.
nebx Learn
GitHub
Menu
JS

JavaScript

The language of the web, on the client, the server and the edge.

Paradigm
Multi-paradigm, prototype-based, functional
Typing
Dynamic, weak (TypeScript adds static types)
Memory
Garbage collected
Runs
V8 / SpiderMonkey / JSC engines (JIT)
Concurrency
Single-threaded event loop, workers
Structural pattern

Facade

Intent

Provides a simplified interface to a library, framework or other complex set of classes.

Problem

Converting a video needs a dozen classes from a codec library in the right order.

Solution

A facade class exposes the few operations clients need and handles the complexity inside.

Real-world analogy

Think of it like this

Ordering by phone: one operator talks to the warehouse, payment and delivery for you.

Structure

association / extends implements / depends on
Client 4 Facade - linksToSubsystemObjects+ subsystemOperation() 1 AdditionalFacade + anotherOperation() 2 SubsystemA SubsystemB 3 SubsystemC

Hover or tap a numbered role to highlight it in the diagram.

  1. 1Facade — Facade gives convenient access to a particular part of the subsystem.
  2. 2AdditionalFacade — Additional Facades keep one facade from becoming a god object.
  3. 3SubsystemB — The Complex Subsystem is dozens of objects that don't know the facade exists.
  4. 4Client — Client calls the facade instead of the subsystem objects directly.

Code example

A JavaScript code sample for Facade is coming soon. Factory Method, Singleton, Decorator, Observer and Strategy already have code in all six languages.

Applicability

Use Facade when you need a limited, straightforward interface to a complex subsystem.

Use Facade when structuring a subsystem into layers.

Pros and cons

Pros

  • Isolates code from subsystem complexity

Cons

  • Can become a god object coupled to everything

Relations with other patterns

Check yourself

Check yourself

Expose one simple convert(video, format) call over a complex codec library.

Saved in this browser only. Part of Structural patterns (0/7).