The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or "god" object.
SubsystemOne
and SubsystemThree
do not
interact with the internal components of SubsystemTwo
.
They use the SubsystemTwoWrapper
"facade" (i.e. the
higher level abstraction).
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]
Adapter and Facade are both wrappers; but they are different kinds of wrappers. The intent of Facade is to produce a simpler interface, and the intent of Adapter is to design to an existing interface. While Facade routinely wraps multiple objects and Adapter wraps a single object; Facade could front-end a single complex object and Adapter could wrap several legacy objects. [Design Patterns Explained, p105]
Question: So the way to tell the difference between the
Adapter pattern and the Facade pattern is that the Adapter wraps
one class and the Facade may represent many classes?
Answer: No! Remember, the Adapter pattern changes the
interface of one or more classes into one interface that a client
is expecting. While most textbook examples show the adapter
adapting one class, you may need to adapt many classes to provide
the interface a client is coded to. Likewise, a Facade may
provide a simplified interface to a single class with a very
complex interface. The difference between the two is not in
terms of how many classes they "wrap", it is in their intent.
[Head First Design Patterns, p260]