<s>
The	O
abstract	B-Language
factory	I-Language
pattern	I-Language
in	O
software	B-General_Concept
engineering	I-General_Concept
is	O
a	O
design	O
that	O
provides	O
a	O
way	O
to	O
create	O
families	O
of	O
related	O
objects	O
without	O
imposing	O
their	O
concrete	O
classes	O
,	O
by	O
encapsulating	O
a	O
group	O
of	O
individual	O
factories	B-Application
that	O
have	O
a	O
common	O
theme	O
without	O
specifying	O
their	O
concrete	O
classes	O
.	O
</s>
<s>
According	O
to	O
this	O
pattern	O
,	O
a	O
client	B-Protocol
software	I-Protocol
component	O
creates	O
a	O
concrete	O
implementation	O
of	O
the	O
abstract	B-Language
factory	I-Language
and	O
then	O
uses	O
the	O
generic	O
interface	B-Application
of	O
the	O
factory	O
to	O
create	O
the	O
concrete	O
objects	O
that	O
are	O
part	O
of	O
the	O
family	O
.	O
</s>
<s>
The	O
client	B-Protocol
does	O
not	O
know	O
which	O
concrete	O
objects	O
it	O
receives	O
from	O
each	O
of	O
these	O
internal	O
factories	B-Application
,	O
as	O
it	O
uses	O
only	O
the	O
generic	O
interfaces	O
of	O
their	O
products	O
.	O
</s>
<s>
This	O
pattern	O
separates	O
the	O
details	O
of	O
implementation	O
of	O
a	O
set	O
of	O
objects	O
from	O
their	O
general	O
usage	O
and	O
relies	O
on	O
object	O
composition	O
,	O
as	O
object	O
creation	O
is	O
implemented	O
in	O
methods	O
exposed	O
in	O
the	O
factory	O
interface	B-Application
.	O
</s>
<s>
Use	O
of	O
this	O
pattern	O
enables	O
interchangeable	O
concrete	O
implementations	O
without	O
changing	O
the	O
code	O
that	O
uses	O
them	O
,	O
even	O
at	B-Library
runtime	I-Library
.	O
</s>
<s>
The	O
abstract	B-Language
factory	I-Language
design	O
pattern	O
is	O
one	O
of	O
the	O
23	O
patterns	O
described	O
in	O
the	O
1994	O
Design	O
Patterns	O
book	O
.	O
</s>
<s>
This	O
allows	O
for	O
new	O
derived	O
types	O
to	O
be	O
introduced	O
with	O
no	O
change	O
to	O
the	O
code	O
that	O
uses	O
the	O
base	B-Application
class	I-Application
.	O
</s>
<s>
Encapsulate	B-Application
object	O
creation	O
in	O
a	O
separate	O
(	O
factory	O
)	O
object	O
by	O
defining	O
and	O
implementing	O
an	O
interface	B-Application
for	O
creating	O
objects	O
.	O
</s>
<s>
Delegate	O
object	O
creation	O
to	O
a	O
factory	B-Application
object	I-Application
instead	O
of	O
creating	O
objects	O
directly	O
.	O
</s>
<s>
A	O
class	O
may	O
be	O
configured	O
with	O
a	O
factory	B-Application
object	I-Application
,	O
which	O
it	O
uses	O
to	O
create	O
objects	O
,	O
and	O
the	O
factory	B-Application
object	I-Application
can	O
be	O
exchanged	O
at	B-Library
runtime	I-Library
.	O
</s>
<s>
The	O
Design	O
Patterns	O
book	O
describes	O
the	O
abstract	B-Language
factory	I-Language
pattern	I-Language
as	O
"	O
an	O
interface	B-Application
for	O
creating	O
families	O
of	O
related	O
or	O
dependent	O
objects	O
without	O
specifying	O
their	O
concrete	O
classes.	O
"	O
</s>
<s>
This	O
insulates	O
client	B-Protocol
code	O
from	O
object	O
creation	O
by	O
having	O
clients	O
request	O
that	O
a	O
factory	B-Application
object	I-Application
create	O
an	O
object	O
of	O
the	O
desired	O
abstract	O
type	O
and	O
return	O
an	O
abstract	O
pointer	O
to	O
the	O
object	O
.	O
</s>
<s>
An	O
example	O
is	O
an	O
abstract	B-Language
factory	I-Language
class	O
DocumentCreator	O
that	O
provides	O
interfaces	O
to	O
create	O
a	O
number	O
of	O
products	O
(	O
e.g.	O
,	O
createLetter( )	O
and	O
createResume( )	O
)	O
.	O
</s>
<s>
Each	O
of	O
these	O
products	O
is	O
derived	O
from	O
a	O
simple	O
abstract	O
class	O
such	O
asLetter	O
or	O
Resume	O
of	O
which	O
the	O
client	B-Protocol
is	O
aware	O
.	O
</s>
<s>
The	O
client	B-Protocol
code	O
would	O
acquire	O
an	O
appropriate	O
instance	O
of	O
the	O
DocumentCreator	O
and	O
call	O
its	O
factory	B-Language
methods	I-Language
.	O
</s>
<s>
The	O
client	B-Protocol
would	O
only	O
need	O
to	O
know	O
how	O
to	O
handle	O
the	O
abstract	O
Letter	O
or	O
Resume	O
class	O
,	O
not	O
the	O
specific	O
version	O
that	O
was	O
created	O
by	O
the	O
concrete	O
factory	O
.	O
</s>
<s>
As	O
the	O
factory	O
only	O
returns	O
a	O
reference	O
or	O
a	O
pointer	O
to	O
an	O
abstract	O
type	O
,	O
the	O
client	B-Protocol
code	O
that	O
requested	O
the	O
object	O
from	O
the	O
factory	O
is	O
not	O
aware	O
ofand	O
is	O
not	O
burdened	O
bythe	O
actual	O
concrete	O
type	O
of	O
the	O
object	O
that	O
was	O
created	O
.	O
</s>
<s>
However	O
,	O
the	O
type	O
of	O
a	O
concrete	O
object	O
(	O
and	O
hence	O
a	O
concrete	O
factory	O
)	O
is	O
known	O
by	O
the	O
abstract	B-Language
factory	I-Language
;	O
for	O
instance	O
,	O
the	O
factory	O
may	O
read	O
it	O
from	O
a	O
configuration	O
file	O
.	O
</s>
<s>
The	O
client	B-Protocol
has	O
no	O
need	O
to	O
specify	O
the	O
type	O
,	O
as	O
the	O
type	O
has	O
already	O
been	O
specified	O
in	O
the	O
configuration	O
file	O
.	O
</s>
<s>
The	O
client	B-Protocol
code	O
has	O
no	O
knowledge	O
whatsoever	O
of	O
the	O
concrete	O
type	O
,	O
not	O
needing	O
to	O
include	O
any	O
header	B-Language
files	I-Language
or	O
class	O
declarations	O
related	O
to	O
it	O
.	O
</s>
<s>
The	O
client	B-Protocol
code	O
deals	O
only	O
with	O
the	O
abstract	O
type	O
.	O
</s>
<s>
Objects	O
of	O
a	O
concrete	O
type	O
are	O
indeed	O
created	O
by	O
the	O
factory	O
,	O
but	O
the	O
client	B-Protocol
code	O
accesses	O
such	O
objects	O
only	O
through	O
their	O
abstract	B-Architecture
interfaces	I-Architecture
.	O
</s>
<s>
Adding	O
new	O
concrete	O
types	O
is	O
performed	O
by	O
modifying	O
the	O
client	B-Protocol
code	O
to	O
use	O
a	O
different	O
factory	O
,	O
a	O
modification	O
that	O
is	O
typically	O
one	O
line	O
in	O
one	O
file	O
.	O
</s>
<s>
The	O
different	O
factory	O
then	O
creates	O
objects	O
of	O
a	O
different	O
concrete	O
type	O
but	O
still	O
returns	O
a	O
pointer	O
of	O
the	O
same	O
abstract	O
type	O
as	O
before	O
,	O
thus	O
insulating	O
the	O
client	B-Protocol
code	O
from	O
change	O
.	O
</s>
<s>
This	O
is	O
significantly	O
easier	O
than	O
is	O
modifying	O
the	O
client	B-Protocol
code	O
to	O
instantiate	O
a	O
new	O
type	O
,	O
which	O
would	O
require	O
changing	O
every	O
location	O
in	O
the	O
code	O
where	O
a	O
new	O
object	O
is	O
created	O
as	O
well	O
as	O
ensuring	O
that	O
all	O
such	O
code	O
locations	O
have	O
knowledge	O
of	O
the	O
new	O
concrete	O
type	O
,	O
for	O
example	O
,	O
by	O
including	O
a	O
concrete	O
class	O
header	B-Language
file	I-Language
.	O
</s>
<s>
If	O
all	O
factory	B-Application
objects	I-Application
are	O
stored	O
globally	O
in	O
a	O
singleton	O
object	O
,	O
and	O
all	O
client	B-Protocol
code	O
passes	O
through	O
the	O
singleton	O
to	O
access	O
the	O
proper	O
factory	O
for	O
object	O
creation	O
,	O
then	O
changing	O
factories	B-Application
is	O
as	O
easy	O
as	O
changing	O
the	O
singleton	O
object	O
.	O
</s>
<s>
In	O
the	O
above	O
UML	B-Language
class	O
diagram	O
,	O
</s>
<s>
the	O
Client	B-Protocol
class	O
that	O
requires	O
ProductA	O
and	O
ProductB	O
objects	O
does	O
not	O
instantiate	O
the	O
ProductA1	O
and	O
ProductB1	O
classes	O
directly	O
.	O
</s>
<s>
Instead	O
,	O
the	O
Client	B-Protocol
refers	O
to	O
the	O
AbstractFactory	O
interface	B-Application
for	O
creating	O
objects	O
,	O
which	O
makes	O
the	O
Client	B-Protocol
independent	O
of	O
how	O
the	O
objects	O
are	O
created	O
(	O
which	O
concrete	O
classes	O
are	O
instantiated	O
)	O
.	O
</s>
<s>
The	O
Factory1	O
class	O
implements	O
the	O
AbstractFactory	O
interface	B-Application
by	O
instantiating	O
the	O
ProductA1	O
and	O
ProductB1	O
classes	O
.	O
</s>
<s>
The	O
UML	B-Language
sequence	O
diagram	O
shows	O
the	O
runtime	B-Library
interactions	O
.	O
</s>
<s>
The	O
Client	B-Protocol
object	O
calls	O
createProductA( )	O
on	O
the	O
Factory1	O
object	O
,	O
which	O
creates	O
and	O
returns	O
a	O
ProductA1	O
object	O
.	O
</s>
<s>
Thereafter	O
,	O
the	O
Client	B-Protocol
calls	O
createProductB( )	O
on	O
Factory1	O
,	O
which	O
creates	O
and	O
returns	O
a	O
ProductB1	O
object	O
.	O
</s>
<s>
The	O
original	O
structure	O
of	O
the	O
abstract	B-Language
factory	I-Language
pattern	I-Language
,	O
as	O
defined	O
in	O
the	O
Design	O
Patterns	O
book	O
in	O
1994	O
,	O
is	O
based	O
on	O
abstract	O
classes	O
for	O
the	O
abstract	B-Language
factory	I-Language
and	O
the	O
abstract	O
products	O
to	O
be	O
created	O
.	O
</s>
<s>
The	O
concrete	O
factories	B-Application
and	O
products	O
are	O
classes	O
that	O
specialize	O
the	O
abstract	O
classes	O
using	O
inheritance	O
.	O
</s>
<s>
A	O
more	O
recent	O
structure	O
of	O
the	O
pattern	O
is	O
based	O
on	O
interfaces	O
that	O
define	O
the	O
abstract	B-Language
factory	I-Language
and	O
the	O
abstract	O
products	O
to	O
be	O
created	O
.	O
</s>
<s>
The	O
concrete	O
factories	B-Application
and	O
products	O
are	O
in	O
this	O
case	O
classes	O
that	O
realize	O
the	O
interface	B-Application
by	O
implementing	O
it	O
.	O
</s>
<s>
Alternative	O
implementation	O
using	O
the	O
classes	O
themselves	O
as	O
factories	B-Application
:	O
</s>
