Facade
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.
Problem
A segment of the client community needs a simplified interface to the
overall functionality of a complex subsystem.
Discussion
Facade discusses encapsulating a complex subsystem within a single
interface object. This reduces the learning curve necessary to
successfully leverage the subsystem. It also promotes decoupling the
subsystem from its potentially many clients. On the other hand, if the
Facade is the only access point for the subsystem, it will limit the
features and flexibility that "power users" may need.
The Facade object should be a fairly simple advocate or facilitator. It
should not become an all-knowing oracle or "god" object.
Structure
Example
The Facade defines a unified, higher level interface to a subsystem
that makes it easier to use. Consumers encounter a Facade when
ordering from a catalog. The consumer calls one number and speaks with
a customer service representative. The customer service representative
acts as a Facade, providing an interface to the order fulfillment
department, the billing department, and the shipping department.
[Michael Duell, "Non-software examples of software design
patterns", Object Magazine, Jul 97, p54]
Non-software example
Rules of thumb
Facade defines a new interface, whereas Adapter uses an old interface.
Remember that Adapter makes two existing interfaces work together as
opposed to defining an entirely new one. [GOF, p219]
Whereas Flyweight shows how to make lots of little objects, Facade
shows how to make a single object represent an entire subsystem. [GOF,
p138]
Mediator is similar to Facade in that it abstracts functionality of
existing classes. Mediator abstracts/centralizes arbitrary
communications between colleague objects. It routinely "adds value",
and it is known/referenced by the colleague objects. In contrast,
Facade defines a simpler interface to a subsystem, it doesn't add new
functionality, and it is not known by the subsystem classes. [GOF.
p193]
Abstract Factory can be used as an alternative to Facade to hide
platform-specific classes. [GOF, p193]
Facade objects are often Singletons because only one Facade object is
required. [GOF, p193]
C++ Demos | Java
Demos