Definition

“Facade pattern provides a unified interface to a set of interfaces in a subsystem. It makes the subsystem easier to use by providing a higher-level interface”

Explanation

You create a single Facade class that wraps a complex subsystem of many classes and offers simplified methods. The client calls the facade’s easy methods, which internally call the appropriate subsystem classes. This hides subsystem complexity and reduces coupling. Subsystem classes can still be used directly if needed, but clients can rely on the facade for common tasks.

Code

Here, ConcreteComponent is wrapped by decorators. ConcreteDecoratorA and ConcreteDecoratorB extend the behavior of ConcreteComponent without modifying its code. The client_code function shows how a component and its decorated versions behave.
class Subsystem1:
    def operation1(self):
        return "Subsystem1: Ready!"
    def operation2(self):
        return "Subsystem1: Go!"

class Subsystem2:
    def operation1(self):
        return "Subsystem2: Get ready!"
    def operation2(self):
        return "Subsystem2: Fire!"

class Facade:
    def __init__(self):
        self._subsystem_1 = Subsystem1()
        self._subsystem_2 = Subsystem2()

    def operation(self):
        results = []
        results.append("Facade initializes subsystems:")
        results.append(self._subsystem_1.operation1())
        results.append(self._subsystem_1.operation2())
        results.append(self._subsystem_2.operation1())
        results.append(self._subsystem_2.operation2())
        return "\n".join(results)

def main():
    facade = Facade()
    print(facade.operation())

if __name__ == "__main__":
    main()

Analogy

A universal remote control: instead of dealing with each device (TV, stereo, DVD) separately, the remote provides simple buttons like “Watch Movie” that internally powers on the correct devices. Or the main menu at a restaurant: instead of asking the kitchen multiple questions (do you have onions, peppers, gluten?), the menu (facade) hides those details.

Interview Insights

Use Case: Simplify complex libraries or subsystems. Provide a simple interface for cross-cutting functionality (e.g. APIs that wrap multiple backend calls). Useful when evolving a complex system while maintaining compatibility.
Advantages: PReduces learning curve for clients. Decouples client from subsystem. Makes code more readable/maintainable.
Disadvantages: The facade can become a “God object” if it tries to do too much. Clients may still need direct access to subsystem classes for advanced features. It adds one more layer of indirection.
Common questions: “How is Facade different from Adapter/Decorator?”, “Example of facade (e.g. wrapper for media library)”, “When NOT to use Facade?”, “Discuss principle of least knowledge (Law of Demeter) in relation to facade”.\