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.
What the interviewer is probing.
1. "What does a Facade give you?" *Probing:* the purpose. *Stalls:* "Simplicity." *Moves up:* one simple entry point to a complex subsystem, so callers are not coupled to its internal classes and ordering.
2. "Does it prevent access to the subsystem?" *Probing:* the precision. *Stalls:* "Yes." *Moves up:* no — it is a convenience, not a restriction; advanced callers can still use the subsystem directly.
3. "When does a facade become a problem?" *Probing:* the judgement. *Stalls:* "Never." *Moves up:* when it grows into a god object that every feature adds to, which is a sign the subsystem needs splitting instead.
4. "How does it relate to a service layer?" *Probing:* the practical connection. *Stalls:* "Not at all." *Moves up:* an application service is usually a facade over domain and infrastructure, which is why the pattern appears without being named.
A hotel concierge — you ask to book a restaurant and taxi. The concierge handles the coordination.
Key Concepts
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");