Pattern Comparison

The Adapter pattern has much in common with the patterns discussed in Chapter 2. The differences are in the intents of the patterns. A bridge, for example, separates an interface and its implementation so that they can vary independently, whereas an adapter changes the interface of an existing object. The Adapter pattern is more useful for one-off changes, whereas the Bridge pattern anticipates that change might happen continuously.

A decorator enhances an object without changing its interface and should be transparent to the application. An adapter is not transparent, as it is the named implementation of the interface the client sees. The Proxy pattern does not change any interfaces; it defines substitute objects for other objects.

From a certain point of view, the Façade pattern is also adapting requests: it transforms high-level requests into a sequence of lower-level requests. The Façade's intent is to hide complexity, and the Façade subsystems are not intended to be accessible by the client.

To complete the picture, we can classify the Adapter and Façade patterns according to the mechanisms shown in Table 4-2.

Table 4-2. Comparison of Adapter and Façade patterns

Mechanism

Adapter

Façade

Original

Adaptee

SubsystemA, B, and C

Interface

ITarget

Façade

New

Adapter

Operation1 and 2

Client

Aggregates ITarget

Accesses Façade

Client activates

New

New

Original changed by

No change

No change

New classes/subsystems

Adapter provides adaptations to their methods

Façade supplies high-level operations

Operation routed

From new to original

From new to original

Get C# 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.