What is the Facade pattern?
Why Interviewers Ask This
This tests whether you can apply OOP Concepts knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
The Facade pattern provides a simplified, unified interface to a complex subsystem — hiding the complexity and dependencies within. Like a hotel concierge — you make one request and they coordinate the complex details. Complex subsystem: class AudioSystem { public void turnOn() { } public void setVolume(int level) { } public void selectSource(String source) { } public void turnOff() { } } class VideoSystem { public void turnOn() { } public void setResolution(String res) { } public void selectInput(String input) { } public void turnOff() { } } class LightingSystem { public void dimLights(int percent) { } public void setColor(String color) { } public void brightLights() { } } class Projector { public void deploy() { } public void setAspectRatio(String ratio) { } public void retract() { } } // Facade -- simple interface to the complex home theater: class HomeTheaterFacade { private AudioSystem audio; private VideoSystem video; private LightingSystem lights; private Projector projector; public HomeTheaterFacade(AudioSystem audio, VideoSystem video, LightingSystem lights, Projector projector) { this.audio = audio; this.video = video; this.lights = lights; this.projector = projector; } // Simple operations: public void watchMovie(String movie) { lights.dimLights(20); lights.setColor("warm"); projector.deploy(); projector.setAspectRatio("16:9"); video.turnOn(); video.setResolution("4K"); video.selectInput("HDMI-1"); audio.turnOn(); audio.setVolume(70); audio.selectSource("HDMI"); System.out.println("Movie ready: " + movie); } public void endMovie() { audio.turnOff(); video.turnOff(); projector.retract(); lights.brightLights(); } } // Client -- simple interface: HomeTheaterFacade theater = new HomeTheaterFacade(audio, video, lights, projector); theater.watchMovie("Inception"); theater.endMovie();. Benefits: simplifies complex APIs, reduces coupling between client and subsystem, provides a simple entry point. Used heavily in frameworks and APIs.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.