Adapter Pattern

CSC-430

Phillip Wright

Adapters

We briefly discussed adapters earlier in the semester when discussing decorators, but didn’t go into much detail, because there is very little difference. For the sake of completeness, let’s review briefly.

The Adapter Pattern

Converts the interface of a class to another interface expected by clients. Lets classes work together that couldn’t otherwise because of incompatible interfaces

AKA: Wrapper

Adapters II

As mentioned before, the main difference between decorators and adapters is that decorators implement the same interface as what is being wrapped, while adapters use a different interface.

Adapters III

Note that when using adapters we lose the benefits of transparency that we obtain from using decorators.

Accordingly, we can “stack” decorators, but can only have one adapter of a given kind.

The Facade Pattern

Provides a unified interface to a set of interfaces in a subsystem. Defines a higher level interface that makes the subsystems easier to use.

Facades

We can view facades as, basically, adapters which adapt multiple complex interfaces to a single, simple interface. In other words, they will often “wrap” more than one object, and expose their functionality in an adapted interface.