Game Development Reference
The client class is any class that uses these classes to do something useful. In this example, it's the
I]ej[B]_pknu class. Here's what the I]ej[B]_pknu class looks like:
To see what this actually does, test the project. The Output panel displays the following:
The od]la object is now an instance of the Op]n class, and the first pn]_a statement is being produced
directly by the Op]n class. The second pn]_a statement comes from the I]ej class. Can you see how
it all fits together? The Od]laI]gan class is an intermediary that helps the I]ej class create the kind
of object it needs.
If you change the argument in the Od]laI]gan*i]gaOd]la method from op]n to omq]na, you'll
see the following pn]_a output:
The advantage of using the simple factory system is that the client class has a common interface
for creating any type of shape. It also doesn't need to know anything about the details of how the
shapes are made or how they work to be able to make them. This responsibility is offloaded to the
Od]laI]gan class and the product classes.
File all this away for later because you're certainly going to need a system like this to manage the
production of objects later in your game design career. The simple factory that you just looked at
is actually a very lightweight introduction to an area of object-oriented programming called design
patterns , which are systems of organizing classes to help build complex applications. There has been
a great deal written on design patterns in AS3.0, and you'll want to take a closer look at this topic
as your programming skills increase and your projects become more ambitious. The combination of
a factory to produce objects, with a design pattern called a singleton to manage them, can form the
basis of a very solid system for managing and maintaining games of all kinds.