<s>
In	O
object-oriented	B-Language
programming	I-Language
,	O
forwarding	B-Application
means	O
that	O
using	O
a	O
member	O
of	O
an	O
object	O
(	O
either	O
a	O
property	B-Language
or	O
a	O
method	B-Language
)	O
results	O
in	O
actually	O
using	O
the	O
corresponding	O
member	O
of	O
a	O
different	O
object	O
:	O
the	O
use	O
is	O
forwarded	O
to	O
another	O
object	O
.	O
</s>
<s>
Forwarding	B-Application
is	O
used	O
in	O
a	O
number	O
of	O
design	O
patterns	O
,	O
where	O
some	O
members	O
are	O
forwarded	O
to	O
another	O
object	O
,	O
while	O
others	O
are	O
handled	O
by	O
the	O
directly	O
used	O
object	O
.	O
</s>
<s>
The	O
forwarding	B-Application
object	O
is	O
frequently	O
called	O
a	O
wrapper	O
object	O
,	O
and	O
explicit	O
forwarding	B-Application
members	O
are	O
called	O
wrapper	O
functions	O
.	O
</s>
<s>
Forwarding	B-Application
is	O
often	O
confused	O
with	O
delegation	B-Application
;	O
formally	O
,	O
they	O
are	O
complementary	O
concepts	O
.	O
</s>
<s>
In	O
both	O
cases	O
,	O
there	O
are	O
two	O
objects	O
,	O
and	O
the	O
first	O
(	O
sending	O
,	O
wrapper	O
)	O
object	O
uses	O
the	O
second	O
(	O
receiving	O
,	O
wrappee	O
)	O
object	O
,	O
for	O
example	O
to	O
call	O
a	O
method	B-Language
.	O
</s>
<s>
They	O
differ	O
in	O
what	O
self	B-Application
refers	O
to	O
on	O
the	O
receiving	O
object	O
(	O
formally	O
,	O
in	O
the	O
evaluation	O
environment	O
of	O
the	O
method	B-Language
on	O
the	O
receiving	O
object	O
)	O
:	O
in	O
delegation	B-Application
it	O
refers	O
to	O
the	O
sending	O
object	O
,	O
while	O
in	O
forwarding	B-Application
it	O
refers	O
to	O
the	O
receiving	O
object	O
.	O
</s>
<s>
Note	O
that	O
self	B-Application
is	O
often	O
used	O
implicitly	O
as	O
part	O
of	O
dynamic	O
dispatch	O
(	O
method	B-Language
resolution	O
:	O
which	O
function	O
a	O
method	B-Language
name	I-Language
refers	O
to	O
)	O
.	O
</s>
<s>
under	O
delegation	B-Application
this	O
will	O
output	O
m2	O
,	O
n1	O
because	O
n( )	O
is	O
evaluated	O
in	O
the	O
context	O
of	O
the	O
original	O
(	O
sending	O
)	O
object	O
,	O
while	O
under	O
forwarding	B-Application
this	O
will	O
output	O
m2	O
,	O
n2	O
because	O
n( )	O
is	O
evaluated	O
in	O
the	O
context	O
of	O
the	O
receiving	O
object	O
.	O
</s>
<s>
In	O
casual	O
use	O
,	O
forwarding	B-Application
is	O
often	O
referred	O
to	O
as	O
"	O
delegation	B-Application
"	O
,	O
or	O
considered	O
a	O
form	O
of	O
delegation	B-Application
,	O
but	O
in	O
careful	O
usage	O
they	O
are	O
clearly	O
distinguished	O
by	O
what	O
self	B-Application
refers	O
to	O
.	O
</s>
<s>
While	O
delegation	B-Application
is	O
analogous	O
to	O
inheritance	B-Language
,	O
allowing	O
behavioral	O
reuse	O
(	O
and	O
concretely	O
code	O
reuse	O
)	O
without	O
changing	O
evaluation	O
context	O
,	O
forwarding	B-Application
is	O
analogous	O
to	O
composition	B-Language
,	O
as	O
execution	O
depends	O
only	O
on	O
the	O
receiving	O
(	O
member	O
)	O
object	O
,	O
not	O
the	O
(	O
original	O
)	O
sending	O
object	O
.	O
</s>
<s>
Like	O
inheritance	B-Language
,	O
delegation	B-Application
allows	O
the	O
sending	O
object	O
to	O
modify	O
the	O
original	O
behavior	O
,	O
but	O
is	O
susceptible	O
to	O
problems	O
analogous	O
to	O
the	O
fragile	B-Application
base	I-Application
class	I-Application
;	O
while	O
forwarding	B-Application
provides	O
stronger	O
encapsulation	O
and	O
avoids	O
these	O
problems	O
;	O
see	O
composition	B-Library
over	I-Library
inheritance	I-Library
.	O
</s>
<s>
A	O
simple	O
example	O
of	O
explicit	O
forwarding	B-Application
in	O
Java	B-Language
:	O
an	O
instance	O
of	O
B	O
forwards	O
calls	O
to	O
the	O
foo	O
method	B-Language
of	O
its	O
a	O
field	O
:	O
</s>
<s>
Indeed	O
,	O
A	O
need	O
not	O
even	O
be	O
a	O
class	O
:	O
it	O
may	O
be	O
an	O
interface/protocol	O
.	O
</s>
<s>
Contrast	O
with	O
inheritance	B-Language
,	O
in	O
which	O
foo	O
is	O
defined	O
in	O
a	O
superclass	O
A	O
(	O
which	O
must	O
be	O
a	O
class	O
,	O
not	O
an	O
interface	O
)	O
,	O
and	O
when	O
called	O
on	O
an	O
instance	O
of	O
a	O
subclass	O
B	O
,	O
it	O
uses	O
the	O
code	O
defined	O
in	O
A	O
,	O
but	O
the	O
this	O
object	O
is	O
still	O
an	O
instance	O
of	O
B	O
:	O
</s>
<s>
In	O
this	O
Python	O
example	O
,	O
class	O
B	O
forwards	O
the	O
foo	O
method	B-Language
and	O
the	O
x	O
property	B-Language
to	O
the	O
object	O
in	O
its	O
a	O
field	O
:	O
using	O
these	O
on	O
b	O
(	O
an	O
instance	O
of	O
B	O
)	O
is	O
the	O
same	O
as	O
using	O
them	O
on	O
b.a	O
(	O
the	O
instance	O
of	O
A	O
to	O
which	O
these	O
are	O
forwarded	O
)	O
.	O
</s>
<s>
In	O
this	O
Java	B-Language
example	O
,	O
the	O
class	O
has	O
a	O
method	B-Language
.	O
</s>
<s>
This	O
print	O
method	B-Language
,	O
rather	O
than	O
performing	O
the	O
print	O
itself	O
,	O
forwards	O
to	O
an	O
object	O
of	O
class	O
.	O
</s>
<s>
Forwarding	B-Application
is	O
simply	O
passing	O
a	O
duty	O
off	O
to	O
someone/something	O
else	O
.	O
</s>
<s>
The	O
more	O
complex	O
case	O
is	O
a	O
Decorator	O
Pattern	O
that	O
by	O
using	O
interfaces	B-Language
,	O
forwarding	B-Application
can	O
be	O
made	O
more	O
flexible	O
and	O
typesafe	B-Language
.	O
</s>
<s>
"	O
Flexibility	O
"	O
here	O
means	O
that	O
need	O
not	O
refer	O
to	O
or	O
in	O
any	O
way	O
,	O
as	O
the	O
switching	O
of	O
forwarding	B-Application
is	O
abstracted	O
from	O
.	O
</s>
<s>
In	O
this	O
example	O
,	O
class	O
can	O
forward	O
to	O
any	O
class	O
that	O
implements	B-Language
an	O
interface	O
.	O
</s>
<s>
Class	O
has	O
a	O
method	B-Language
to	O
switch	O
to	O
another	O
forwarder	O
.	O
</s>
<s>
Including	O
the	O
clauses	O
improves	O
type	B-Language
safety	I-Language
,	O
because	O
each	O
class	O
must	O
implement	O
the	O
methods	O
in	O
the	O
interface	O
.	O
</s>
<s>
Forwarding	B-Application
is	O
used	O
in	O
many	O
design	O
patterns	O
.	O
</s>
<s>
Forwarding	B-Application
is	O
used	O
directly	O
in	O
several	O
patterns	O
:	O
</s>
<s>
Decorator	O
pattern	O
:	O
decorator	O
object	O
adds	O
its	O
own	O
members	O
,	O
forwarding	B-Application
others	O
to	O
the	O
decorated	O
object	O
.	O
</s>
<s>
Forwarding	B-Application
may	O
be	O
used	O
in	O
other	O
patterns	O
,	O
but	O
often	O
use	O
is	O
modified	O
;	O
for	O
example	O
,	O
a	O
method	B-Language
call	I-Language
on	O
one	O
object	O
results	O
in	O
several	O
different	O
methods	O
being	O
called	O
on	O
another	O
:	O
</s>
