Applied Design Patterns with Java
Structural :: Facade (185) {C ch 13}
Intent
Provide a unified interface to a set of interfaces in a subsystem.
Facade
defines a higher-level interface that makes the subsystem easier to use.
Motivation
Structuring a system into subsystems helps reduce complexity.
A common design goal is to minimize the communication
and dependencies between subsystems. One way to achieve
this goal is to introduce a Facade object that provides
a single, simplified interface to the more general facilities of a subsystem.
A programming environment gives applications access to its compiler subsystem containing classes such as Scanner,
Parser,
ProgramNode, BytecodeStream, and ProgramNodeBuilder that implement the compiler. Specialized applications might need
to access these classes directly. But most clients of a compiler don't care about details like parsing and code
generation; they merely want to compile some code. The powerful but low-level interfaces in the compiler subsystem
only complicate their task. To provide a higher-level interface that can shield clients from these classes, the compiler subsystem
also includes a Compiler class. This class defines a unified interface to the compiler's functionality.
The Compiler class acts as a Facade: It offers clients a single, simple interface to the compiler subsystem.
It glues together the classes that implement compiler functionality without hiding them completely. The compiler
Facade makes life easier for most programmers without hiding the lower-level functionality from
the few that need it.