<s>
In	O
object-oriented	B-Language
programming	I-Language
languages	I-Language
,	O
a	O
mixin	B-Language
(	O
or	O
mix-in	O
)	O
is	O
a	O
class	O
that	O
contains	O
methods	B-Language
for	O
use	O
by	O
other	O
classes	O
without	O
having	O
to	O
be	O
the	O
parent	O
class	O
of	O
those	O
other	O
classes	O
.	O
</s>
<s>
How	O
those	O
other	O
classes	O
gain	O
access	O
to	O
the	O
mixin	B-Language
's	O
methods	B-Language
depends	O
on	O
the	O
language	O
.	O
</s>
<s>
Mixins	B-Language
are	O
sometimes	O
described	O
as	O
being	O
"	O
included	O
"	O
rather	O
than	O
"	O
inherited	O
"	O
.	O
</s>
<s>
Mixins	B-Language
encourage	O
code	O
reuse	O
and	O
can	O
be	O
used	O
to	O
avoid	O
the	O
inheritance	B-Language
ambiguity	O
that	O
multiple	B-Application
inheritance	I-Application
can	O
cause	O
(	O
the	O
"	O
diamond	O
problem	O
"	O
)	O
,	O
or	O
to	O
work	O
around	O
lack	O
of	O
support	O
for	O
multiple	B-Application
inheritance	I-Application
in	O
a	O
language	O
.	O
</s>
<s>
A	O
mixin	B-Language
can	O
also	O
be	O
viewed	O
as	O
an	O
interface	B-Application
with	O
implemented	O
methods	B-Language
.	O
</s>
<s>
Mixins	B-Language
first	O
appeared	O
in	O
Symbolics	O
's	O
object-oriented	B-Language
Flavors	B-Language
system	O
(	O
developed	O
by	O
Howard	O
Cannon	O
)	O
,	O
which	O
was	O
an	O
approach	O
to	O
object-orientation	O
used	O
in	O
Lisp	B-Language
Machine	I-Language
Lisp	I-Language
.	O
</s>
<s>
Mixins	B-Language
are	O
a	O
language	O
concept	O
that	O
allows	O
a	O
programmer	O
to	O
inject	O
some	O
code	O
into	O
a	O
class	O
.	O
</s>
<s>
Mixin	B-Language
programming	O
is	O
a	O
style	O
of	O
software	O
development	O
,	O
in	O
which	O
units	O
of	O
functionality	O
are	O
created	O
in	O
a	O
class	O
and	O
then	O
mixed	O
in	O
with	O
other	O
classes	O
.	O
</s>
<s>
A	O
mixin	B-Language
class	I-Language
acts	O
as	O
the	O
parent	O
class	O
,	O
containing	O
the	O
desired	O
functionality	O
.	O
</s>
<s>
Typically	O
,	O
the	O
mixin	B-Language
will	O
export	O
the	O
desired	O
functionality	O
to	O
a	O
child	O
class	O
,	O
without	O
creating	O
a	O
rigid	O
,	O
single	O
"	O
is	O
a	O
"	O
relationship	O
.	O
</s>
<s>
Here	O
lies	O
the	O
important	O
difference	O
between	O
the	O
concepts	O
of	O
mixins	B-Language
and	O
inheritance	B-Language
,	O
in	O
that	O
the	O
child	O
class	O
can	O
still	O
inherit	O
all	O
the	O
features	O
of	O
the	O
parent	O
class	O
,	O
but	O
,	O
the	O
semantics	O
about	O
the	O
child	O
"	O
being	O
a	O
kind	O
of	O
"	O
the	O
parent	O
need	O
not	O
be	O
necessarily	O
applied	O
.	O
</s>
<s>
It	O
provides	O
a	O
mechanism	O
for	O
multiple	B-Application
inheritance	I-Application
by	O
allowing	O
one	O
class	O
to	O
use	O
common	O
functionality	O
from	O
multiple	O
classes	O
,	O
but	O
without	O
the	O
complex	O
semantics	O
of	O
multiple	B-Application
inheritance	I-Application
.	O
</s>
<s>
Code	O
reusability	O
:	O
Mixins	B-Language
are	O
useful	O
when	O
a	O
programmer	O
wants	O
to	O
share	O
functionality	O
between	O
different	O
classes	O
.	O
</s>
<s>
Instead	O
of	O
repeating	O
the	O
same	O
code	O
over	O
and	O
over	O
again	O
,	O
the	O
common	O
functionality	O
can	O
simply	O
be	O
grouped	O
into	O
a	O
mixin	B-Language
and	O
then	O
included	O
into	O
each	O
class	O
that	O
requires	O
it	O
.	O
</s>
<s>
Mixins	B-Language
allow	O
inheritance	B-Language
and	O
use	O
of	O
only	O
the	O
desired	O
features	O
from	O
the	O
parent	O
class	O
,	O
not	O
necessarily	O
all	O
of	O
the	O
features	O
from	O
the	O
parent	O
class	O
.	O
</s>
<s>
In	O
Simula	B-Language
,	O
classes	O
are	O
defined	O
in	O
a	O
block	O
in	O
which	O
attributes	O
,	O
methods	B-Language
and	O
class	O
initialization	O
are	O
all	O
defined	O
together	O
;	O
thus	O
all	O
the	O
methods	B-Language
that	O
can	O
be	O
invoked	O
on	O
a	O
class	O
are	O
defined	O
together	O
,	O
and	O
the	O
definition	O
of	O
the	O
class	O
is	O
complete	O
.	O
</s>
<s>
In	O
Flavors	B-Language
,	O
a	O
mixin	B-Language
is	O
a	O
class	O
from	O
which	O
another	O
class	O
can	O
inherit	O
slot	O
definitions	O
and	O
methods	B-Language
.	O
</s>
<s>
The	O
mixin	B-Language
usually	O
does	O
not	O
have	O
direct	O
instances	O
.	O
</s>
<s>
Since	O
a	O
Flavor	O
can	O
inherit	O
from	O
more	O
than	O
one	O
other	O
Flavor	O
,	O
it	O
can	O
inherit	O
from	O
one	O
or	O
more	O
mixins	B-Language
.	O
</s>
<s>
Note	O
that	O
the	O
original	O
Flavors	B-Language
did	O
not	O
use	O
generic	O
functions	O
.	O
</s>
<s>
In	O
New	B-Language
Flavors	I-Language
(	O
a	O
successor	O
of	O
Flavors	B-Language
)	O
and	O
CLOS	B-Application
,	O
methods	B-Language
are	O
organized	O
in	O
"	O
generic	O
functions	O
"	O
.	O
</s>
<s>
These	O
generic	O
functions	O
are	O
functions	O
that	O
are	O
defined	O
in	O
multiple	O
cases	O
(	O
methods	B-Language
)	O
by	O
class	O
dispatch	O
and	O
method	O
combinations	O
.	O
</s>
<s>
CLOS	B-Application
and	O
Flavors	B-Language
allow	O
mixin	B-Language
methods	B-Language
to	O
add	O
behavior	O
to	O
existing	O
methods	B-Language
:	O
:before	O
and	O
:after	O
daemons	O
,	O
whoppers	O
and	O
wrappers	O
in	O
Flavors	B-Language
.	O
</s>
<s>
CLOS	B-Application
added	O
:around	O
methods	B-Language
and	O
the	O
ability	O
to	O
call	O
shadowed	O
methods	B-Language
via	O
.	O
</s>
<s>
So	O
,	O
for	O
example	O
,	O
a	O
stream-lock-mixin	O
can	O
add	O
locking	O
around	O
existing	O
methods	B-Language
of	O
a	O
stream	O
class	O
.	O
</s>
<s>
In	O
Flavors	B-Language
one	O
would	O
write	O
a	O
wrapper	O
or	O
a	O
whopper	O
and	O
in	O
CLOS	B-Application
one	O
would	O
use	O
an	O
:around	O
method	O
.	O
</s>
<s>
Both	O
CLOS	B-Application
and	O
Flavors	B-Language
allow	O
the	O
computed	O
reuse	O
via	O
method	O
combinations	O
.	O
</s>
<s>
:before	O
,	O
:after	O
and	O
:around	O
methods	B-Language
are	O
a	O
feature	O
of	O
the	O
standard	O
method	O
combination	O
.	O
</s>
<s>
An	O
example	O
is	O
the	O
+	O
method	O
combination	O
,	O
where	O
the	O
resulting	O
values	O
of	O
each	O
of	O
the	O
applicable	O
methods	B-Language
of	O
a	O
generic	O
function	O
are	O
arithmetically	O
added	O
to	O
compute	O
the	O
return	O
value	O
.	O
</s>
<s>
This	O
is	O
used	O
,	O
for	O
example	O
,	O
with	O
the	O
border-mixin	O
for	O
graphical	O
objects	O
.	O
</s>
<s>
The	O
border-mixin	O
would	O
add	O
a	O
border	O
around	O
an	O
object	O
and	O
has	O
a	O
method	O
computing	O
its	O
width	O
.	O
</s>
<s>
A	O
new	O
class	O
bordered-button	O
(	O
that	O
is	O
both	O
a	O
graphical	O
object	O
and	O
uses	O
the	O
border	O
mixin	B-Language
)	O
would	O
compute	O
its	O
width	O
by	O
calling	O
all	O
applicable	O
width	O
methods	B-Language
—	O
via	O
the	O
+	O
method	O
combination	O
.	O
</s>
<s>
In	O
an	O
OOPSLA	O
90	O
paper	O
,	O
Gilad	O
Bracha	O
and	O
William	O
Cook	O
reinterpret	O
different	O
inheritance	B-Language
mechanisms	O
found	O
in	O
Smalltalk	B-Application
,	O
Beta	O
and	O
CLOS	B-Application
as	O
special	O
forms	O
of	O
a	O
mixin	B-Language
inheritance	B-Language
.	O
</s>
<s>
Other	O
than	O
Flavors	B-Language
and	O
CLOS	B-Application
(	O
a	O
part	O
of	O
Common	B-Language
Lisp	I-Language
)	O
,	O
some	O
languages	O
that	O
use	O
mixins	B-Language
are	O
:	O
</s>
<s>
D	B-Application
(	O
called	O
;	O
D	B-Application
also	O
includes	O
a	O
statement	O
that	O
compiles	O
strings	O
as	O
code	O
.	O
)	O
</s>
<s>
Some	O
languages	O
do	O
not	O
support	O
mixins	B-Language
on	O
the	O
language	O
level	O
,	O
but	O
can	O
easily	O
mimic	O
them	O
by	O
copying	O
methods	B-Language
from	O
one	O
object	O
to	O
another	O
at	O
runtime	O
,	O
thereby	O
"	O
borrowing	O
"	O
the	O
mixin	B-Language
's	O
methods	B-Language
.	O
</s>
<s>
This	O
is	O
also	O
possible	O
with	O
statically	O
typed	O
languages	O
,	O
but	O
it	O
requires	O
constructing	O
a	O
new	O
object	O
with	O
the	O
extended	O
set	O
of	O
methods	B-Language
.	O
</s>
<s>
Other	O
languages	O
that	O
do	O
not	O
support	O
mixins	B-Language
can	O
support	O
them	O
in	O
a	O
round-about	O
way	O
via	O
other	O
language	O
constructs	O
.	O
</s>
<s>
For	O
example	O
,	O
Visual	B-Language
Basic	I-Language
.NET	I-Language
and	O
C#	B-Application
support	O
the	O
addition	O
of	O
extension	O
methods	B-Language
on	O
interfaces	O
,	O
meaning	O
any	O
class	O
implementing	O
an	O
interface	B-Application
with	O
extension	O
methods	B-Language
defined	O
will	O
have	O
the	O
extension	O
methods	B-Language
available	O
as	O
pseudo-members	O
.	O
</s>
<s>
Common	B-Language
Lisp	I-Language
provides	O
mixins	B-Language
in	O
CLOS	B-Application
(	O
Common	B-Application
Lisp	I-Application
Object	I-Application
System	I-Application
)	O
similar	O
to	O
Flavors	B-Language
.	O
</s>
<s>
This	O
combination	O
determines	O
that	O
all	O
applicable	O
methods	B-Language
for	O
a	O
generic	O
function	O
will	O
be	O
called	O
and	O
the	O
results	O
will	O
be	O
added	O
.	O
</s>
<s>
bordered-button	O
is	O
a	O
class	O
inheriting	O
from	O
both	O
border-mixin	O
and	O
button	O
.	O
</s>
<s>
The	O
result	O
is	O
the	O
sum	O
of	O
the	O
results	O
of	O
the	O
two	O
applicable	O
methods	B-Language
:	O
the	O
method	O
object-width	O
for	O
the	O
class	O
button	O
and	O
the	O
method	O
object-width	O
for	O
the	O
class	O
border-mixin	O
.	O
</s>
<s>
In	O
Python	B-Language
,	O
an	O
example	O
of	O
the	O
mixin	B-Language
concept	O
is	O
found	O
in	O
the	O
SocketServer	O
module	O
,	O
which	O
has	O
both	O
a	O
UDPServer	O
class	O
and	O
a	O
TCPServer	O
class	O
.	O
</s>
<s>
They	O
act	O
as	O
servers	O
for	O
UDP	B-Protocol
and	O
TCP	B-Protocol
socket	O
servers	O
,	O
respectively	O
.	O
</s>
<s>
Additionally	O
,	O
there	O
are	O
two	O
mixin	B-Language
classes	I-Language
:	O
ForkingMixIn	O
and	O
ThreadingMixIn	O
.	O
</s>
<s>
the	O
ThreadingMixIn	O
class	O
adds	O
functionality	O
to	O
the	O
TCP	B-Protocol
server	O
such	O
that	O
each	O
new	O
connection	O
creates	O
a	O
new	O
thread	B-Operating_System
.	O
</s>
<s>
Alternatively	O
,	O
using	O
the	O
ForkingMixIn	O
would	O
cause	O
the	O
process	O
to	O
be	O
forked	B-Language
for	O
each	O
new	O
connection	O
.	O
</s>
<s>
Clearly	O
,	O
the	O
functionality	O
to	O
create	O
a	O
new	O
thread	B-Operating_System
or	O
fork	B-Language
a	O
process	O
is	O
not	O
terribly	O
useful	O
as	O
a	O
stand-alone	O
class	O
.	O
</s>
<s>
In	O
this	O
usage	O
example	O
,	O
the	O
mixins	B-Language
provide	O
alternative	O
underlying	O
functionality	O
without	O
affecting	O
the	O
functionality	O
as	O
a	O
socket	O
server	O
.	O
</s>
<s>
Most	O
of	O
the	O
Ruby	B-Language
world	O
is	O
based	O
around	O
mixins	B-Language
via	O
Modules	O
.	O
</s>
<s>
The	O
concept	O
of	O
mixins	B-Language
is	O
implemented	O
in	O
Ruby	B-Language
by	O
the	O
keyword	O
include	O
to	O
which	O
we	O
pass	O
the	O
name	O
of	O
the	O
module	O
as	O
parameter	O
.	O
</s>
<s>
In	O
the	O
Curl	B-Language
web-content	O
language	O
,	O
multiple	B-Application
inheritance	I-Application
is	O
used	O
as	O
classes	O
with	O
no	O
instances	O
may	O
implement	O
methods	B-Language
.	O
</s>
<s>
Common	O
mixins	B-Language
include	O
all	O
skinnable	O
ControlUIs	O
inheriting	O
from	O
SkinnableControlUI	O
,	O
user	O
interface	B-Application
delegate	O
objects	O
that	O
require	O
dropdown	O
menus	O
inheriting	O
from	O
StandardBaseDropdownUI	O
and	O
such	O
explicitly	O
named	O
mixin	B-Language
classes	I-Language
as	O
FontGraphicMixin	O
,	O
FontVisualMixin	O
and	O
NumericAxisMixin-of	O
class	O
.	O
</s>
<s>
Version	O
7.0	O
added	O
library	O
access	O
so	O
that	O
mixins	B-Language
do	O
not	O
need	O
to	O
be	O
in	O
the	O
same	O
package	O
or	O
be	O
public	O
abstract	O
.	O
</s>
<s>
Curl	B-Language
constructors	O
are	O
factories	O
that	O
facilitates	O
using	O
multiple-inheritance	O
without	O
explicit	O
declaration	O
of	O
either	O
interfaces	O
or	O
mixins	B-Language
.	O
</s>
<s>
Java	B-Language
8	O
introduces	O
a	O
new	O
feature	O
in	O
the	O
form	O
of	O
default	O
methods	B-Language
for	O
interfaces	O
.	O
</s>
<s>
Basically	O
it	O
allows	O
a	O
method	O
to	O
be	O
defined	O
in	O
an	O
interface	B-Application
with	O
application	O
in	O
the	O
scenario	O
when	O
a	O
new	O
method	O
is	O
to	O
be	O
added	O
to	O
an	O
interface	B-Application
after	O
the	O
interface	B-Application
class	O
programming	O
setup	O
is	O
done	O
.	O
</s>
<s>
To	O
add	O
a	O
new	O
function	O
to	O
the	O
interface	B-Application
means	O
to	O
implement	O
the	O
method	O
at	O
every	O
class	O
which	O
uses	O
the	O
interface	B-Application
.	O
</s>
<s>
Default	O
methods	B-Language
help	O
in	O
this	O
case	O
where	O
they	O
can	O
be	O
introduced	O
to	O
an	O
interface	B-Application
any	O
time	O
and	O
have	O
an	O
implemented	O
structure	O
which	O
is	O
then	O
used	O
by	O
the	O
associated	O
classes	O
.	O
</s>
<s>
Hence	O
default	O
methods	B-Language
add	O
the	O
ability	O
to	O
applying	O
the	O
mixin	B-Language
concept	O
in	O
Java	B-Language
.	O
</s>
<s>
Interfaces	O
combined	O
with	O
aspect-oriented	B-Architecture
programming	I-Architecture
can	O
also	O
produce	O
full-fledged	O
mixins	B-Language
in	O
languages	O
that	O
support	O
such	O
features	O
,	O
such	O
as	O
C#	B-Application
or	O
Java	B-Language
.	O
</s>
<s>
Additionally	O
,	O
through	O
the	O
use	O
of	O
the	O
marker	B-Language
interface	I-Language
pattern	I-Language
,	O
generic	B-Language
programming	I-Language
,	O
and	O
extension	O
methods	B-Language
,	O
C#	B-Application
3.0	O
has	O
the	O
ability	O
to	O
mimic	O
mixins	B-Language
.	O
</s>
<s>
With	O
Dart	B-Language
2.7	O
and	O
C#	B-Application
3.0	O
came	O
the	O
introduction	O
of	O
extension	O
methods	B-Language
which	O
can	O
be	O
applied	O
,	O
not	O
only	O
to	O
classe	O
,	O
but	O
also	O
to	O
interfaces	O
.	O
</s>
<s>
Extension	O
Methods	B-Language
provide	O
additional	O
functionality	O
on	O
an	O
existing	O
class	O
without	O
modifying	O
the	O
class	O
.	O
</s>
<s>
It	O
then	O
becomes	O
possible	O
to	O
create	O
a	O
static	O
helper	O
class	O
for	O
specific	O
functionality	O
that	O
defines	O
the	O
extension	O
methods	B-Language
.	O
</s>
<s>
Because	O
the	O
classes	O
implement	O
the	O
interface	B-Application
(	O
even	O
if	O
the	O
actual	O
interface	B-Application
does	O
n’t	O
contain	O
any	O
methods	B-Language
or	O
properties	O
to	O
implement	O
)	O
it	O
will	O
pick	O
up	O
all	O
the	O
extension	O
methods	B-Language
also	O
.	O
</s>
<s>
C#	B-Application
8.0	O
adds	O
the	O
feature	O
of	O
default	O
interface	B-Application
methods	B-Language
.	O
</s>
<s>
ECMAScript	B-Language
(	O
in	O
most	O
cases	O
implemented	O
as	O
JavaScript	O
)	O
does	O
not	O
need	O
to	O
mimic	O
object	O
composition	O
by	O
stepwise	O
copying	O
fields	O
from	O
one	O
object	O
to	O
another	O
.	O
</s>
<s>
It	O
natively	O
supports	O
Trait	O
and	O
mixin	B-Language
based	O
object	O
composition	O
via	O
function	O
objects	O
that	O
implement	O
additional	O
behavior	O
and	O
then	O
are	O
delegated	O
via	O
call	O
or	O
apply	O
to	O
objects	O
that	O
are	O
in	O
need	O
of	O
such	O
new	O
functionality	O
.	O
</s>
<s>
Scala	B-Application
has	O
a	O
rich	O
type	O
system	O
and	O
Traits	O
are	O
a	O
part	O
of	O
it	O
which	O
helps	O
implement	O
mixin	B-Language
behaviour	O
.	O
</s>
<s>
Here	O
,	O
Bird	O
has	O
mixed	O
in	O
all	O
methods	B-Language
of	O
the	O
trait	O
into	O
its	O
own	O
definition	O
as	O
if	O
class	O
Bird	O
had	O
defined	O
method	O
sing( )	O
on	O
its	O
own	O
.	O
</s>
<s>
As	O
extends	O
is	O
also	O
used	O
to	O
inherit	O
from	O
a	O
super	O
class	O
,	O
in	O
case	O
of	O
a	O
trait	O
extends	O
is	O
used	O
if	O
no	O
super	O
class	O
is	O
inherited	O
and	O
only	O
for	O
mixin	B-Language
in	O
the	O
first	O
trait	O
.	O
</s>
<s>
Scala	B-Application
allows	O
mixing	O
in	O
a	O
trait	O
(	O
creating	O
an	O
anonymous	B-Language
type	I-Language
)	O
when	O
creating	O
a	O
new	O
instance	O
of	O
a	O
class	O
.	O
</s>
<s>
Rust	B-Application
makes	O
extensive	O
use	O
of	O
mixins	B-Language
via	O
traits	O
.	O
</s>
<s>
Traits	O
,	O
like	O
in	O
Scala	B-Application
,	O
allow	O
users	O
to	O
implement	O
behaviours	O
for	O
a	O
defined	O
type	O
.	O
</s>
<s>
They	O
are	O
also	O
used	O
for	O
generics	B-Language
and	O
dynamic	O
dispatch	O
,	O
which	O
allow	O
for	O
types	O
with	O
same	O
traits	O
to	O
be	O
used	O
interchangeably	O
statically	O
or	O
dynamically	O
at	O
runtime	O
respectively	O
.	O
</s>
<s>
Mixin	B-Language
can	O
be	O
achieved	O
in	O
Swift	B-Application
by	O
using	O
a	O
language	O
feature	O
called	O
Default	O
implementation	O
in	O
Protocol	O
Extension	O
.	O
</s>
