<s>
Duck	B-Application
typing	I-Application
in	O
computer	O
programming	O
is	O
an	O
application	O
of	O
the	O
duck	O
test	O
"	O
If	O
it	O
walks	O
like	O
a	O
duck	O
and	O
it	O
quacks	O
like	O
a	O
duck	O
,	O
then	O
it	O
must	O
be	O
a	O
duck	O
"	O
to	O
determine	O
whether	O
an	O
object	O
can	O
be	O
used	O
for	O
a	O
particular	O
purpose	O
.	O
</s>
<s>
With	O
nominative	O
typing	O
,	O
an	O
object	O
is	O
of	O
a	O
given	O
type	O
if	O
it	O
is	O
declared	O
to	O
be	O
(	O
or	O
if	O
a	O
type	O
's	O
association	O
with	O
the	O
object	O
is	O
inferred	O
through	O
mechanisms	O
such	O
as	O
object	B-Language
inheritance	I-Language
)	O
.	O
</s>
<s>
In	O
duck	B-Application
typing	I-Application
,	O
an	O
object	O
is	O
of	O
a	O
given	O
type	O
if	O
it	O
has	O
all	O
methods	B-Language
and	O
properties	O
required	O
by	O
that	O
type	O
.	O
</s>
<s>
Duck	B-Application
typing	I-Application
can	O
be	O
viewed	O
as	O
a	O
usage-based	O
structural	O
equivalence	O
between	O
a	O
given	O
object	O
and	O
the	O
requirements	O
of	O
a	O
type	O
.	O
</s>
<s>
This	O
is	O
a	O
simple	O
example	O
in	O
Python	B-Language
3	O
that	O
demonstrates	O
how	O
any	O
object	O
may	O
be	O
used	O
in	O
any	O
context	O
,	O
up	O
until	O
it	O
is	O
used	O
in	O
a	O
way	O
that	O
it	O
does	O
not	O
support	O
.	O
</s>
<s>
In	O
some	O
statically	O
typed	O
languages	O
such	O
as	O
Boo	B-Application
and	O
D	O
,	O
class	O
type	O
checking	O
can	O
be	O
specified	O
to	O
occur	O
at	O
run	B-Library
time	I-Library
rather	O
than	O
compile	O
time	O
.	O
</s>
<s>
Duck	B-Application
typing	I-Application
is	O
similar	O
to	O
,	O
but	O
distinct	O
from	O
,	O
structural	O
typing	O
.	O
</s>
<s>
Structural	O
typing	O
is	O
a	O
static	O
typing	O
system	O
that	O
determines	O
type	O
compatibility	O
and	O
equivalence	O
by	O
a	O
type	O
's	O
structure	O
,	O
whereas	O
duck	B-Application
typing	I-Application
is	O
dynamic	O
and	O
determines	O
type	O
compatibility	O
by	O
only	O
that	O
part	O
of	O
a	O
type	O
's	O
structure	O
that	O
is	O
accessed	O
during	O
run	B-Library
time	I-Library
.	O
</s>
<s>
The	O
TypeScript	B-Language
,	O
Elm	B-Language
,	O
and	O
Python	B-Language
languages	I-Language
support	O
structural	O
typing	O
to	O
varying	O
degrees	O
.	O
</s>
<s>
Protocols	B-Application
and	I-Application
interfaces	I-Application
provide	O
a	O
way	O
to	O
declare	O
,	O
explicitly	O
,	O
that	O
some	O
methods	B-Language
,	O
operators	O
,	O
or	O
behaviors	O
need	O
to	O
be	O
defined	O
(	O
e.g.	O
</s>
<s>
In	O
contrast	O
,	O
under	O
duck	B-Application
typing	I-Application
,	O
the	O
object	O
would	O
be	O
accepted	O
directly	O
,	O
without	O
the	O
need	O
for	O
an	O
adaptor	O
.	O
</s>
<s>
Template	B-Language
,	O
or	O
generic	B-Language
functions	O
or	O
methods	B-Language
apply	O
the	O
duck	O
test	O
in	O
a	O
static	O
typing	O
context	O
;	O
this	O
brings	O
all	O
the	O
advantages	O
and	O
disadvantages	O
of	O
static	O
versus	O
dynamic	O
type	O
checking	O
in	O
general	O
.	O
</s>
<s>
Duck	B-Application
typing	I-Application
can	O
also	O
be	O
more	O
flexible	O
in	O
that	O
only	O
the	O
methods	B-Language
actually	O
called	O
at	B-Library
runtime	I-Library
need	O
to	O
be	O
implemented	O
,	O
while	O
templates	O
require	O
implementations	O
of	O
all	O
methods	B-Language
that	O
can	O
not	O
be	O
proven	O
unreachable	O
at	O
compile	O
time	O
.	O
</s>
<s>
In	O
languages	O
like	O
Java	B-Language
,	O
Scala	O
,	O
and	O
Objective-C	O
,	O
reflection	B-Language
can	O
be	O
used	O
to	O
inspect	O
whether	O
objects	O
implement	O
methods	B-Language
or	O
even	O
add	O
necessary	O
methods	B-Language
at	B-Library
runtime	I-Library
.	O
</s>
<s>
For	O
example	O
,	O
Java	B-Language
's	O
can	O
be	O
used	O
in	O
this	O
manner	O
.	O
</s>
