Facade
You'll learn to
- -Explain Facade as one simple entry point over several classes that must be used together
- -See with numbers how a facade removes repeated, order-sensitive code
- -Know that Facade usually appears as a "this is getting complicated" follow-up, and what must not go inside it
Walk into a hotel and say "I'd like a table for two at eight". You do not phone the kitchen, the dining room manager and the cloakroom separately. The concierge handles all of that, and you deal with one person. The Facade pattern is the concierge of a program: a single, simple entry point placed in front of a group of classes that must be used together, in a particular order.
Facade does not hide the other classes. Callers who need fine control can still use the underlying classes directly, but most callers only ever need the facade.
A Home Theater Example
Starting a movie "properly" might mean dimming the lights, lowering the screen, switching on the projector, setting the sound to surround and choosing the streaming input. That is five calls on four different objects, in the right order, every time. Run the demo to see the facade replace those five calls by one.
The saving grows with the number of callers. Suppose 12 different screens in an app start a movie.
If the order ever changes, say "dim the lights after lowering the screen", you fix one method instead of 12 copies, and nobody can forget a step.
When It Shows Up as a Follow-Up
Facade rarely appears in the first requirements of an LLD prompt. It usually arrives as the answer to "this is getting complicated, how would you simplify the API for new callers?" after you have built several subsystem classes. The moment to spot is: "three or four classes always get used together in the same sequence, and most callers should not need to know that sequence." Introducing a facade there feels natural, not bolted on.
A facade adds no new functionality. It only simplifies access to what already exists. If you find yourself writing new business logic inside the facade, that logic 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.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!