The Facade pattern is a structural pattern that provides a single, simplified interface in front of a complex subsystem of classes. Clients interact with the facade instead of learning and coordinating every underlying component directly.
Key Points: • The facade exposes a small set of high-level methods that internally coordinate multiple subsystem calls. • Clients no longer need to understand the internal structure or ordering requirements of the subsystem. • It reduces coupling between client code and the individual subsystem classes. • The subsystem classes remain fully accessible directly for clients that need finer-grained control. • It's commonly used to wrap legacy systems or third-party libraries with a cleaner API.
Example: A HomeTheaterFacade might expose a single watchMovie() method that internally dims the lights, powers on the projector, and starts the DVD player, so the client doesn't need to call each subsystem in the correct order themselves.
Interview Tip: A concise interview answer is:
"Facade simplifies interactions with a complex system by putting a single, high-level interface in front of multiple subsystem classes, so clients call one or two simple methods instead of coordinating many components and their ordering themselves."