<s>
In	O
software	B-General_Concept
engineering	I-General_Concept
,	O
the	O
adapter	O
pattern	O
is	O
a	O
software	O
design	O
pattern	O
(	O
also	O
known	O
as	O
wrapper	O
,	O
an	O
alternative	O
naming	O
shared	O
with	O
the	O
decorator	O
pattern	O
)	O
that	O
allows	O
the	O
interface	B-Language
of	O
an	O
existing	O
class	O
to	O
be	O
used	O
as	O
another	O
interface	B-Language
.	O
</s>
<s>
An	O
example	O
is	O
an	O
adapter	O
that	O
converts	O
the	O
interface	B-Language
of	O
a	O
Document	B-General_Concept
Object	I-General_Concept
Model	I-General_Concept
of	O
an	O
XML	B-Protocol
document	I-Protocol
into	O
a	O
tree	O
structure	O
that	O
can	O
be	O
displayed	O
.	O
</s>
<s>
How	O
can	O
a	O
class	O
be	O
reused	O
that	O
does	O
not	O
have	O
an	O
interface	B-Language
that	O
a	O
client	O
requires	O
?	O
</s>
<s>
How	O
can	O
classes	O
that	O
have	O
incompatible	O
interfaces	B-Application
work	O
together	O
?	O
</s>
<s>
How	O
can	O
an	O
alternative	O
interface	B-Language
be	O
provided	O
for	O
a	O
class	O
?	O
</s>
<s>
Often	O
an	O
(	O
already	O
existing	O
)	O
class	O
ca	O
n't	O
be	O
reused	O
only	O
because	O
its	O
interface	B-Language
does	O
n't	O
conform	O
to	O
the	O
interface	B-Language
clients	O
require	O
.	O
</s>
<s>
Define	O
a	O
separate	O
adapter	O
class	O
that	O
converts	O
the	O
(	O
incompatible	O
)	O
interface	B-Language
of	O
a	O
class	O
(	O
adaptee	O
)	O
into	O
another	O
interface	B-Language
(	O
target	O
)	O
clients	O
require	O
.	O
</s>
<s>
Work	O
through	O
an	O
adapter	O
to	O
work	O
with	O
(	O
reuse	O
)	O
classes	O
that	O
do	O
not	O
have	O
the	O
required	O
interface	B-Language
.	O
</s>
<s>
The	O
key	O
idea	O
in	O
this	O
pattern	O
is	O
to	O
work	O
through	O
a	O
separate	O
adapter	O
that	O
adapts	O
the	O
interface	B-Language
of	O
an	O
(	O
already	O
existing	O
)	O
class	O
without	O
changing	O
it	O
.	O
</s>
<s>
Clients	O
do	O
n't	O
know	O
whether	O
they	O
work	O
with	O
a	O
target	O
class	O
directly	O
or	O
through	O
an	O
adapter	O
with	O
a	O
class	O
that	O
does	O
not	O
have	O
the	O
target	O
interface	B-Language
.	O
</s>
<s>
See	O
also	O
the	O
UML	B-Language
class	O
diagram	O
below	O
.	O
</s>
<s>
An	O
adapter	O
allows	O
two	O
incompatible	O
interfaces	B-Application
to	O
work	O
together	O
.	O
</s>
<s>
Interfaces	B-Application
may	O
be	O
incompatible	O
,	O
but	O
the	O
inner	O
functionality	O
should	O
suit	O
the	O
need	O
.	O
</s>
<s>
The	O
adapter	O
design	O
pattern	O
allows	O
otherwise	O
incompatible	O
classes	O
to	O
work	O
together	O
by	O
converting	O
the	O
interface	B-Language
of	O
one	O
class	O
into	O
an	O
interface	B-Language
expected	O
by	O
the	O
clients	O
.	O
</s>
<s>
An	O
adapter	O
can	O
be	O
used	O
when	O
the	O
wrapper	O
must	O
respect	O
a	O
particular	O
interface	B-Language
and	O
must	O
support	O
polymorphic	B-Application
behavior	O
.	O
</s>
<s>
Alternatively	O
,	O
a	O
decorator	O
makes	O
it	O
possible	O
to	O
add	O
or	O
alter	O
behavior	O
of	O
an	O
interface	B-Language
at	O
run-time	O
,	O
and	O
a	O
facade	O
is	O
used	O
when	O
an	O
easier	O
or	O
simpler	O
interface	B-Language
to	O
an	O
underlying	O
object	O
is	O
desired	O
.	O
</s>
<s>
In	O
the	O
above	O
UML	B-Language
class	O
diagram	O
,	O
the	O
client	O
class	O
that	O
requires	O
a	O
target	O
interface	B-Language
cannot	O
reuse	O
the	O
adaptee	O
class	O
directly	O
because	O
its	O
interface	B-Language
does	O
n't	O
conform	O
to	O
the	O
target	O
interface	B-Language
.	O
</s>
<s>
Instead	O
,	O
the	O
client	O
works	O
through	O
an	O
adapter	O
class	O
that	O
implements	B-Language
the	O
target	O
interface	B-Language
in	O
terms	O
of	O
adaptee	O
:	O
</s>
<s>
The	O
object	O
adapter	O
way	O
implements	B-Language
the	O
target	O
interface	B-Language
by	O
delegating	O
to	O
an	O
adaptee	O
object	O
at	O
run-time	O
(adaptee.specificOperation( )	O
)	O
.	O
</s>
<s>
The	O
class	O
adapter	O
way	O
implements	B-Language
the	O
target	O
interface	B-Language
by	O
inheriting	O
from	O
an	O
adaptee	O
class	O
at	O
compile-time	O
(specificOperation( )	O
)	O
.	O
</s>
<s>
This	O
adapter	O
pattern	O
uses	O
multiple	O
polymorphic	B-Application
interfaces	B-Application
implementing	O
or	O
inheriting	O
both	O
the	O
interface	B-Language
that	O
is	O
expected	O
and	O
the	O
interface	B-Language
that	O
is	O
pre-existing	O
.	O
</s>
<s>
It	O
is	O
typical	O
for	O
the	O
expected	O
interface	B-Language
to	O
be	O
created	O
as	O
a	O
pure	O
interface	B-Language
class	O
,	O
especially	O
in	O
languages	O
such	O
as	O
Java	B-Language
(	O
before	O
JDK	O
1.8	O
)	O
that	O
do	O
not	O
support	O
multiple	B-Application
inheritance	I-Application
of	O
classes	O
.	O
</s>
<s>
and	O
perhaps	O
create	O
the	O
correctly	O
"	O
formatting	O
"	O
object	O
at	O
runtime	O
by	O
means	O
of	O
the	O
factory	B-Application
pattern	I-Application
.	O
</s>
