Facade
You'll learn to
- -Provide a simplified interface over a complex subsystem without hiding the subsystem entirely
- -Recognize Facade as the pattern most likely to appear as a "clean this up" follow-up rather than a starting requirement
Facade provides a unified, simplified interface to a set of interfaces in a complex subsystem, making the subsystem easier to use without hiding it entirely - callers who need the fine-grained subsystem classes directly can still reach them, but most callers only ever need the facade.
A Home Theater Example
Turning on a home theater "properly" might mean powering on the projector, dimming the lights, starting the sound system, setting the input source, and lowering the screen - five separate subsystem calls in a specific order, every single time. A HomeTheaterFacade.watch_movie() method wraps all five calls behind one method, so the common case ("just start the movie") is one call, while the individual subsystem classes remain available for anyone who genuinely needs finer control.
class HomeTheaterFacade:
def __init__(self, projector, lights, sound_system, screen):
self._projector = projector
self._lights = lights
self._sound_system = sound_system
self._screen = screen
def watch_movie(self) -> None:
self._lights.dim(10)
self._screen.lower()
self._projector.on()
self._sound_system.set_surround_mode()
self._projector.set_input("streaming")
# Most callers just do this - the five-step coordination is hidden, not gone:
theater.watch_movie()When It Shows Up as a Follow-Up, Not a Starting Requirement
Facade rarely appears in the initial requirements of an LLD prompt - it typically shows up as the answer to a follow-up like "this is getting complex, how would you simplify the client-facing API?" after you have already built out several subsystem classes. Recognizing that moment - "I have three or four classes that always get used together in a specific sequence, and most callers do not need that sequence exposed" - and introducing a Facade there is a strong, natural-feeling design move rather than a pattern bolted on from the start.
Facade does not add new functionality - it only simplifies access to functionality that already exists across several classes. If you find yourself adding new business logic inside the facade itself, that logic likely belongs in one of the subsystem classes instead.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.