Applied Design Patterns with Java
Structural :: Facade (185) {C ch 13}
Applicability
Use the Facade pattern when:
- to provide a simple interface to a complex subsystem.
Subsystems often get more complex as they evolve. Most patterns, when applied, result in more and smaller classes.
This makes the subsystem more reusable and easier to customize, but it also becomes harder to use for clients that
don't need to customize it. A Facade can
provide a simple default view of the subsystem that is good enough for most clients. Only clients needing
more customizability will need to look beyond the facade;
- there are many dependencies between clients and the
implementation classes of an abstraction. Introduce a Facade to decouple the subsystem from clients and other subsystems,
thereby promoting subsystem independence and portability;
- to layer subsystems. Use a Facade
to define an entry point to each subsystem level. If subsystems are dependent, then simplify the dependencies between
them by making them communicate with each other solely through their Facades.
Structure
The Facade pattern has this general organization:
Participants
- Facade
(Compiler) knows which subsystem
classes are responsible for a request, and delegates client requests to appropriate subsystem objects.
- Subsystem classes (Scanner, Parser, ProgramNode, etc.)
implement subsystem functionality, handle work
assigned by the Facade object, and have no knowledge of the facade; that is, they keep no references to it.
Catalog Structural Prev Next