<s>
In	O
software	B-General_Concept
engineering	I-General_Concept
,	O
inversion	B-Language
of	I-Language
control	I-Language
(	O
IoC	O
)	O
is	O
a	O
design	O
pattern	O
in	O
which	O
custom-written	O
portions	O
of	O
a	O
computer	B-Application
program	I-Application
receive	O
the	O
flow	O
of	O
control	O
from	O
a	O
generic	O
framework	B-Architecture
.	O
</s>
<s>
A	O
software	B-Architecture
architecture	I-Architecture
with	O
this	O
design	O
inverts	O
control	O
as	O
compared	O
to	O
traditional	O
procedural	B-Application
programming	I-Application
:	O
in	O
traditional	O
programming	O
,	O
the	O
custom	O
code	O
that	O
expresses	O
the	O
purpose	O
of	O
the	O
program	O
calls	O
into	O
reusable	O
libraries	O
to	O
take	O
care	O
of	O
generic	O
tasks	O
,	O
but	O
with	O
inversion	B-Language
of	I-Language
control	I-Language
,	O
it	O
is	O
the	O
framework	B-Architecture
that	O
calls	O
into	O
the	O
custom	O
,	O
or	O
task-specific	O
,	O
code	O
.	O
</s>
<s>
Inversion	B-Language
of	I-Language
control	I-Language
is	O
used	O
to	O
increase	O
modularity	B-Architecture
of	O
the	O
program	O
and	O
make	O
it	O
extensible	B-Application
,	O
and	O
has	O
applications	O
in	O
object-oriented	B-Language
programming	I-Language
and	O
other	O
programming	O
paradigms	O
.	O
</s>
<s>
The	O
term	O
was	O
used	O
by	O
Michael	O
Mattsson	O
in	O
a	O
thesis	O
,	O
taken	O
from	O
there	O
by	O
Stefano	O
Mazzocchi	O
and	O
popularized	O
by	O
him	O
in	O
1999	O
in	O
a	O
defunct	O
Apache	O
Software	O
Foundation	O
project	O
,	O
Avalon	B-Language
,	O
then	O
further	O
popularized	O
in	O
2004	O
by	O
Robert	O
C	O
.	O
Martin	O
and	O
Martin	O
Fowler	O
.	O
</s>
<s>
The	O
term	O
is	O
related	O
to	O
,	O
but	O
different	O
from	O
,	O
the	O
dependency	B-Application
inversion	O
principle	O
,	O
which	O
concerns	O
itself	O
with	O
decoupling	B-Application
dependencies	I-Application
between	O
high-level	O
and	O
low-level	O
layers	B-Architecture
through	O
shared	O
abstractions	B-Application
.	O
</s>
<s>
The	O
general	O
concept	O
is	O
also	O
related	O
to	O
event-driven	B-Application
programming	I-Application
in	O
that	O
it	O
is	O
often	O
implemented	O
using	O
IoC	O
so	O
that	O
the	O
custom	O
code	O
is	O
commonly	O
only	O
concerned	O
with	O
the	O
handling	O
of	O
events	O
,	O
whereas	O
the	O
event	B-General_Concept
loop	I-General_Concept
and	O
dispatch	O
of	O
events/messages	O
is	O
handled	O
by	O
the	O
framework	B-Architecture
or	O
the	O
runtime	B-Library
environment	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
with	O
traditional	O
programming	O
,	O
the	O
main	B-Language
function	I-Language
of	O
an	O
application	O
might	O
make	O
function	O
calls	O
into	O
a	O
menu	O
library	O
to	O
display	O
a	O
list	O
of	O
available	O
commands	B-Application
and	O
query	O
the	O
user	O
to	O
select	O
one	O
.	O
</s>
<s>
The	O
library	O
thus	O
would	O
return	O
the	O
chosen	O
option	O
as	O
the	O
value	O
of	O
the	O
function	O
call	O
,	O
and	O
the	O
main	B-Language
function	I-Language
uses	O
this	O
value	O
to	O
execute	O
the	O
associated	O
command	O
.	O
</s>
<s>
This	O
style	O
was	O
common	O
in	O
text	B-Application
based	I-Application
interfaces	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
an	O
email	B-Protocol
client	I-Protocol
may	O
show	O
a	O
screen	O
with	O
commands	B-Application
to	O
load	O
new	O
mail	O
,	O
answer	O
the	O
current	O
mail	O
,	O
create	O
new	O
mail	O
,	O
etc.	O
,	O
and	O
the	O
program	O
execution	O
would	O
block	O
until	O
the	O
user	O
presses	O
a	O
key	O
to	O
select	O
a	O
command	O
.	O
</s>
<s>
With	O
inversion	B-Language
of	I-Language
control	I-Language
,	O
on	O
the	O
other	O
hand	O
,	O
the	O
program	O
would	O
be	O
written	O
using	O
a	O
software	B-Architecture
framework	I-Architecture
that	O
knows	O
common	O
behavioral	O
and	O
graphical	O
elements	O
,	O
such	O
as	O
windowing	B-Application
systems	I-Application
,	O
menus	O
,	O
controlling	O
the	O
mouse	O
,	O
and	O
so	O
on	O
.	O
</s>
<s>
The	O
custom	O
code	O
"	O
fills	O
in	O
the	O
blanks	O
"	O
for	O
the	O
framework	B-Architecture
,	O
such	O
as	O
supplying	O
a	O
table	O
of	O
menu	O
items	O
and	O
registering	O
a	O
code	O
subroutine	O
for	O
each	O
item	O
,	O
but	O
it	O
is	O
the	O
framework	B-Architecture
that	O
monitors	O
the	O
user	O
's	O
actions	O
and	O
invokes	O
the	O
subroutine	O
when	O
a	O
menu	O
item	O
is	O
selected	O
.	O
</s>
<s>
In	O
the	O
mail	B-Protocol
client	I-Protocol
example	O
,	O
the	O
framework	B-Architecture
could	O
follow	O
both	O
the	O
keyboard	O
and	O
mouse	O
inputs	O
and	O
call	O
the	O
command	O
invoked	O
by	O
the	O
user	O
by	O
either	O
means	O
,	O
and	O
at	O
the	O
same	O
time	O
monitor	O
the	O
network	B-Protocol
interface	I-Protocol
to	O
find	O
out	O
if	O
new	O
messages	O
arrive	O
and	O
refresh	O
the	O
screen	O
when	O
some	O
network	O
activity	O
is	O
detected	O
.	O
</s>
<s>
The	O
same	O
framework	B-Architecture
could	O
be	O
used	O
as	O
the	O
skeleton	O
for	O
a	O
spreadsheet	O
program	O
or	O
a	O
text	O
editor	O
.	O
</s>
<s>
Conversely	O
,	O
the	O
framework	B-Architecture
knows	O
nothing	O
about	O
Web	O
browsers	O
,	O
spreadsheets	O
or	O
text	O
editors	O
;	O
implementing	O
their	O
functionality	O
takes	O
custom	O
code	O
.	O
</s>
<s>
Inversion	B-Language
of	I-Language
control	I-Language
carries	O
the	O
strong	O
connotation	O
that	O
the	O
reusable	O
code	O
and	O
the	O
problem-specific	O
code	O
are	O
developed	O
independently	O
even	O
though	O
they	O
operate	O
together	O
in	O
an	O
application	O
.	O
</s>
<s>
Callbacks	O
,	O
schedulers	O
,	O
event	B-General_Concept
loops	I-General_Concept
,	O
dependency	B-Library
injection	I-Library
,	O
and	O
the	O
template	O
method	O
are	O
examples	O
of	O
design	O
patterns	O
that	O
follow	O
the	O
inversion	B-Language
of	I-Language
control	I-Language
principle	O
,	O
although	O
the	O
term	O
is	O
most	O
commonly	O
used	O
in	O
the	O
context	O
of	O
object-oriented	B-Language
programming	I-Language
.	O
</s>
<s>
Inversion	B-Language
of	I-Language
control	I-Language
serves	O
the	O
following	O
design	O
purposes	O
:	O
</s>
<s>
To	O
focus	O
a	O
module	B-Architecture
on	O
the	O
task	O
it	O
is	O
designed	O
for	O
.	O
</s>
<s>
To	O
free	O
modules	B-Architecture
from	O
assumptions	O
about	O
how	O
other	O
systems	O
do	O
what	O
they	O
do	O
and	O
instead	O
rely	O
on	O
contracts	B-Application
.	O
</s>
<s>
To	O
prevent	O
side	O
effects	O
when	O
replacing	O
a	O
module	B-Architecture
.	O
</s>
<s>
Inversion	B-Language
of	I-Language
control	I-Language
is	O
sometimes	O
facetiously	O
referred	O
to	O
as	O
the	O
"	O
Hollywood	B-Language
Principle	I-Language
:	O
Do	O
n't	O
call	O
us	O
,	O
we	O
'll	O
call	O
you	O
"	O
.	O
</s>
<s>
Inversion	B-Language
of	I-Language
control	I-Language
is	O
not	O
a	O
new	O
term	O
in	O
computer	O
science	O
.	O
</s>
<s>
related	O
to	O
the	O
concept	O
of	O
program	O
inversion	O
described	O
by	O
Michael	O
Jackson	O
in	O
his	O
Jackson	B-Application
Structured	I-Application
Programming	I-Application
methodology	O
in	O
the	O
1970s	O
.	O
</s>
<s>
Dependency	B-Library
injection	I-Library
is	O
a	O
specific	O
type	O
of	O
IoC	O
.	O
</s>
<s>
A	O
service	O
locator	O
such	O
as	O
the	O
Java	B-Language
Naming	I-Language
and	I-Language
Directory	I-Language
Interface	I-Language
(	O
JNDI	B-Language
)	O
is	O
similar	O
.	O
</s>
<s>
In	O
an	O
article	O
by	O
Robert	O
C	O
.	O
Martin	O
,	O
the	O
dependency	B-Application
inversion	O
principle	O
and	O
abstraction	B-Application
by	O
layering	O
come	O
together	O
.	O
</s>
<s>
He	O
describes	O
the	O
decoupling	O
of	O
services	O
by	O
the	O
abstraction	B-Application
of	O
layers	B-Architecture
when	O
he	O
is	O
talking	O
about	O
dependency	B-Application
inversion	O
.	O
</s>
<s>
The	O
principle	O
is	O
used	O
to	O
find	O
out	O
where	O
system	O
borders	O
are	O
in	O
the	O
design	O
of	O
the	O
abstraction	B-Architecture
layers	I-Architecture
.	O
</s>
<s>
In	O
traditional	O
programming	O
,	O
the	O
flow	O
of	O
the	O
business	B-Architecture
logic	I-Architecture
is	O
determined	O
by	O
objects	O
that	O
are	O
statically	O
bound	O
to	O
one	O
another	O
.	O
</s>
<s>
With	O
inversion	B-Language
of	I-Language
control	I-Language
,	O
the	O
flow	O
depends	O
on	O
the	O
object	B-Language
graph	O
that	O
is	O
built	O
up	O
during	O
program	O
execution	O
.	O
</s>
<s>
Such	O
a	O
dynamic	O
flow	O
is	O
made	O
possible	O
by	O
object	B-Language
interactions	O
that	O
are	O
defined	O
through	O
abstractions	B-Application
.	O
</s>
<s>
This	O
run-time	O
binding	O
is	O
achieved	O
by	O
mechanisms	O
such	O
as	O
dependency	B-Library
injection	I-Library
or	O
a	O
service	O
locator	O
.	O
</s>
<s>
In	O
IoC	O
,	O
the	O
code	O
could	O
also	O
be	O
linked	O
statically	O
during	O
compilation	O
,	O
but	O
finding	O
the	O
code	O
to	O
execute	O
by	O
reading	O
its	O
description	O
from	O
external	B-Protocol
configuration	I-Protocol
instead	O
of	O
with	O
a	O
direct	O
reference	O
in	O
the	O
code	O
itself	O
.	O
</s>
<s>
In	O
dependency	B-Library
injection	I-Library
,	O
a	O
dependent	O
object	B-Language
or	O
module	B-Architecture
is	O
coupled	O
to	O
the	O
object	B-Language
it	O
needs	O
at	O
run	B-Library
time	I-Library
.	O
</s>
<s>
Which	O
particular	O
object	B-Language
will	O
satisfy	O
the	O
dependency	B-Application
during	O
program	O
execution	O
typically	O
cannot	O
be	O
known	O
at	O
compile	B-Application
time	I-Application
using	O
static	O
analysis	O
.	O
</s>
<s>
While	O
described	O
in	O
terms	O
of	O
object	B-Language
interaction	O
here	O
,	O
the	O
principle	O
can	O
apply	O
to	O
other	O
programming	O
methodologies	O
besides	O
object-oriented	B-Language
programming	I-Language
.	O
</s>
<s>
In	O
object-oriented	B-Language
programming	I-Language
,	O
there	O
are	O
several	O
basic	O
techniques	O
to	O
implement	O
inversion	B-Language
of	I-Language
control	I-Language
.	O
</s>
<s>
Using	O
dependency	B-Library
injection	I-Library
;	O
for	O
example	O
,	O
</s>
<s>
In	O
a	O
description	O
about	O
inversion	B-Language
of	I-Language
control	I-Language
types	O
,	O
the	O
last	O
one	O
is	O
mentioned	O
.	O
</s>
<s>
Most	O
frameworks	O
such	O
as	O
.NET	B-Application
or	O
Enterprise	B-Language
Java	I-Language
display	O
this	O
pattern	O
:	O
</s>
<s>
It	O
is	O
important	O
,	O
however	O
,	O
that	O
in	O
the	O
a	O
lot	O
of	O
assumptions	O
are	O
made	O
about	O
the	O
data	O
returned	O
by	O
the	O
data	O
access	O
object	B-Language
(	O
DAO	O
)	O
.	O
</s>
<s>
Designing	O
the	O
application	O
in	O
the	O
manner	O
of	O
inversion	B-Language
of	I-Language
control	I-Language
would	O
hand	O
over	O
the	O
control	O
completely	O
to	O
the	O
DAO	O
object	B-Language
.	O
</s>
<s>
This	O
resembles	O
the	O
message-passing	B-Architecture
style	O
that	O
some	O
object-oriented	B-Language
programming	I-Language
languages	I-Language
use	O
.	O
</s>
