creational
Facade
Provide a simplified, unified interface to a complex subsystem.
Some subsystems are powerful but awkward. Video conversion is a good example: decoders, buffers, codecs and mixers, all of which must be used in the right order.
If every caller has to learn that sequence, two things go wrong. The same setup code gets copied around the project. And when the subsystem changes, every one of those copies breaks.
Facade adds one simple entry point that handles the common case. Callers ask for what they want, such as convert(file, format), and the facade deals with the machinery.
A hotel concierge — you ask to book a restaurant and taxi. The concierge handles the coordination.
Key Concepts
1
The facade offers a few methods named after what the caller wants to achieve, not after the steps involved.
2
Inside, it creates the subsystem objects and calls them in the correct order. That knowledge now lives in one place instead of being spread across the codebase.
3
The subsystem stays public. Anyone who needs fine control can still use it directly. The facade is a convenience, not a wall.
4
It also gives you room to move. As long as the facade's methods keep working the same way, you can rewrite everything behind it.
When to use it
- Wrapping a complex library or legacy system
- Simple API over a multi-step workflow
- Clean public API while keeping subsystem details internal
Watch out for
- Tends to grow into a god object — every new use case gets bolted on until the facade is a second, worse API
- Hides the subsystem but does not restrict it: callers can bypass the facade unless access is genuinely limited, so the simplification is a convention, not a guarantee
- One more indirection to step through when debugging, and stack traces get deeper
java
public class VideoConverter {
public File convert(String filename, String format) {
VideoFile file = new VideoFile(filename);
Codec codec = new CodecFactory().getCodec(format);
Buffer buffer = new BitrateReader().read(file, codec);
AudioTrack audio = new AudioMixer().mix(file.getAudioTracks());
return new Encoder().encode(buffer, audio, format);
}
}
// Client: one simple call
File mp4 = new VideoConverter().convert("birthday.ogg", "mp4");