Facade pattern 00:00:00 Make a prediction You will design one task-level operation over several subsystems and specify what happens if a middle step fails. The cinema system selected the display input, but loading the film failed. Should a watch-movie operation still tell the caller that playback started? No. A facade makes the sequence simpler to request, not infallible. Stop before playback, report the appropriate failure, and clean up any partially changed state the contract promises to restore. 00:00:34 The miller's lever One lever starts the mill by engaging gears in order. A jam midway matters even though the customer sees only one lever; pulling harder is not a successful grind. A facade coordinates a task that otherwise exposes several steps. It must own the sequencing and surface meaningful failures without taking away direct access needed by specialist callers. The Facade pattern is a structural design pattern. A facade is a class that offers a simple interface to a subsystem, a group of classes that work together. Many small classes are good for those who build a system, and hard for those who use it. Without a front, each client learns all parts, their order and their numbers. 00:01:17 Start a movie with one call Starting a film requires setting the display input, loading the movie and starting playback. Repeating the sequence across screens invites omissions. A cinema facade exposes one watch action and coordinates the subsystems in the proper order. The player and display retain their own responsibilities. If loading fails, report that outcome and avoid starting an empty player. A useful facade simplifies a whole task while keeping failures visible. Dim the lights and then simulate a projector failure. A one-call facade still owes the caller an accurate result and a choice about restoring the lights. Calling play regardless would turn a convenient success path into a confusing partially completed operation. 00:02:04 Do not force every use through the shortcut A camera's quick capture operation can set exposure, focus and shutter for a standard shot. A photographer needing manual exposure can still use lower-level controls. The facade serves a common workflow; it need not erase the subsystem's advanced capabilities. Let a casual caller capture with defaults. Now give an experienced photographer an exposure override. The shortcut can keep the simple promise while a lower-level camera interface serves the advanced case. Adding every control to a single facade would recreate the complexity it was meant to hide. A convenience method that silently swallows failed steps can make a system less understandable than the lower-level API. When two interfaces simply disagree on units or method names, an adapter handles that narrower translation without inventing a larger workflow. Python: subprocess.run. The documentation recommends run() for all use cases it can handle. For more advanced ones the underlying Popen interface can be used directly: a lever and a side door. Requests: requests.get. One function call. Behind it a Session provides cookies, connection pooling and configuration. Who needs these uses the Session. 00:03:24 Try an interview follow-up Does it break single responsibility, because it knows everything? Its one job is to coordinate one kind of operation for one kind of client. It breaks it when it contains rules, or when it serves several kinds of clients. Then I split it. A home theater facade turns down the lights, starts the projector and begins playback. Suppose the projector fails. Decide whether to restore the lights and what result to return. Test that outcome through the facade. Hiding subsystem vocabulary is useful only if the user can still understand what happened. 00:04:02 What to take with you Collect the wishes of one kind of client. One method per wish, the parts come from outside, the order and the numbers live inside. No arrow goes back. Starting is all or nothing, stopping is as much as possible. Every step with an effect brings its undo.