The Adapter design pattern provides a solution:
Define a separate
Adapter class that
converts the interface of a class (Adaptee)
into another interface (Target)
clients require.
Work through an Adapter
to work with classes that have not the required
interface.
Describing the Adapter in more detail is the theme
of the following sections.
See Applicability section for all problems Adapter can solve.
Adapter object
that adapts the interface
of an (already existing) object.
Target object
or an Adapter.
Adapter:
Target interface
in terms of
(by inheriting from) an
Adaptee
class.
Target interface
in terms of (by delegating to) an
Adaptee
object (adaptee.specificOperation()).
Adaptee
class at compile-time.
An object adapter is
more flexible
because it commits (delegates) to an
Adaptee
object at run-time
(see also Sample Code / Example 1).
Adaptee) more reusable,
it can be configured with an adapter object that
converts the interface of the class into the interface
clients (that want to reuse the class) require.