the subsystem easier to use. Because we know exactly what functionality of the other system we
want to use, we can create a
FACADE
that facilitates and streamlines access to those features and
hides the rest. The
FACADE
does
not
change the model of the underlying system. It should be
written strictly in accordance with the other system's model. Otherwise, you will at best diffuse
responsibility for translation into multiple objects and overload the
FACADE
and at worst end up
creating
yet another model, one that doesn't belong to the other system
or
your own
BOUNDED
CONTEXT
. The
FACADE
belongs in the
BOUNDED CONTEXT
of the other system. It just presents a
friendlier face specialized for your needs.
An
ADAPTER
is a wrapper that allows a client to use a different protocol than that understood by the
implementer of the behavior. When a client sends a message to an
ADAPTER
, it is converted to a
semantically equivalent message and sent on to the "adaptee." The response is converted and
passed back. I'm
using the term
adapter
a little loosely, because the emphasis in Gamma et al.
1995 is on making a wrapped object conform to a standard interface that clients expect, whereas
we get to choose the adapted interface, and the adaptee is probably not even an object. Our
emphasis is on translation between two models, but I think this is consistent with the intent of
ADAPTER
.
For each
SERVICE
we define, we need an
ADAPTER
that supports the
SERVICE'S
interface and knows
how to make equivalent requests
of the other system or its
FACADE
.
The remaining element is the translator. The
ADAPTER'S
job is to know how to make a request. The
actual conversion of conceptual objects or data is a distinct, complex task that can be placed in its
own object, making them both much easier to understand. A translator can be a lightweight object
that is instantiated when needed. It needs no state and does not need to be distributed, because it
belongs with the
ADAPTER(S)
it serves.
Those are the basic elements I use to create an
ANTICORRUPTION LAYER
. There are a few other
considerations.
Typically, the system under design (your subsystem)
will be initiating action, as implied by
Figure 14.8. There are cases, however, when the other subsystem may need to request
something of your subsystem or notify it of some event. An
ANTICORRUPTION LAYER
can be
bidirectional, defining
SERVICES
on both interfaces with their own
ADAPTERS
, potentially using
the same translators with symmetrical translations. Although implementing the
ANTICORRUPTION LAYER
doesn't usually require any change to the other subsystem, it might be
necessary in order to make
the other system call on
SERVICES
of the
ANTICORRUPTION LAYER
.
Do'stlaringiz bilan baham: