190 likes | 297 Views
Façade Pattern. Jeff Schott CS590L Spring 2004. What is a façade?. 1) The principal face or front of a building 2) A false, superficial, or artificial appearance. What is the intent?. Provide a unified interface to a set of interfaces in a subsystem
E N D
Façade Pattern Jeff Schott CS590L Spring 2004
What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance
What is the intent? • Provide a unified interface to a set of interfaces in a subsystem • Define a higher-level interface that makes a subsystem easier to use
Motivation • Structuring a system into subsystems helps reduce complexity • Minimize communication dependencies between subsystems • Introduce a façade that provides a single simplified interface
Example - Compiler Compiler subsystem contains classes: • Scanner • Parser • ProgramNode • BytecodeStream • ProgramNodeBuilder
Most clients don’t care about details like parsing and code generation • Compiler subsystem includes a Compiler class - unified interface
Applicability • Provide a simple interface to a complex system • Reduce dependencies between clients and implementation classes • Layered subsystems - façade provides an entry point to each layer
Benefits • Shields clients from subsystem components • Promotes weak coupling between the subsystem and clients • Doesn’t prevent clients from accessing subsystem classes if necessary
Implementation Considerations • Coupling between clients and the subsystem can be further reduced by making the façade an abstract class • Public v. Private subsystem classes
Related Patterns • Abstract Factory • Mediator • Singleton • Adapter • Decorator