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
Ordering by phone: one operator talks to the warehouse, payment and delivery for you.
Structure
Hover or tap a numbered role to highlight it in the diagram.
- 1Facade — Facade gives convenient access to a particular part of the subsystem.
- 2AdditionalFacade — Additional Facades keep one facade from becoming a god object.
- 3SubsystemB — The Complex Subsystem is dozens of objects that don't know the facade exists.
- 4Client — Client calls the facade instead of the subsystem objects directly.
Code example
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
Expose one simple convert(video, format) call over a complex codec library.
Saved in this browser only. Part of Structural patterns (0/7).