|
fa·çade
also fa·cade
(f -säd )
n.
- The face of a building,
especially the principal face.
- An artificial or deceptive
front: ideological slogans
that were a façade for geopolitical power struggles.
[French, from Italian facciata,
from faccia,
face,
from Vulgar Latin *facia,
from Latin faci s.
See dh - in
Indo-European Roots.]
|
Purpose |
- Provide a simple
interface to a complex system. By implementing
the simpler interface in terms of the backend interface[s], the facade
adds
value.
- Decouple backend API
from the client API. This is useful when
backend API is not sufficiently stable to use as a client API.
- Realize a layer's API.
Consolidate a collection of class's APIs,
hiding the class structure from the client.
An articulation point allows 1 endpoint to move (i.e., interface to
change)
without forcing another endpoint to move. For example, your elbow is an
articulation
point; it allows you to move your hand without moving your upper arm.
A facade is an adaptor
or bridge
when:
- A client is
controlling an object B
- B's interface may
change
- we want to hide these
changes from B's clients.
The solution is to interpose an articulation point A: a class that
presents a stable interface to clients, but which translates a client's
requests to
control B into B's [possibly unstable] interface.
Proxy: we may want to
decouple a service's client interface
from the service's actual API.
|
Structure |
|
Consequences |
The articulation point
is an extra class. If B's interface is stable & simple, then A
is extra baggage. |
Implementation |
- From the client's
standpoint, the backend API is private. Declarations
enforce this:
- The facade and backend classes are in a
separate
package from the client.
- The backend API is package-private
- The
facade API is public.
|
Sample Code |
|
Related Patterns |
Bridge, Adaptor
|