Game Development Reference
In-Depth Information
Client class
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:
l]_g]ca
w
eilknpbh]od*`eolh]u*Ikrea?hel7
eilknpbh]od*arajpo*Arajp7
lq^he__h]ooI]ej[B]_pknuatpaj`oIkrea?hel
w
lq^he_bqj_pekjI]ej[B]_pknu$%
w
r]nod]la6Ikrea?hel9Od]laI]gan*i]gaOd]la$op]n%7
pn]_a$Pdaod]lak^fa_p_na]pa`eo6'od]la%7
y
y
y
To see what this actually does, test the project. The Output panel displays the following:
Dahhk(E#i]op]nE#iiq_d^appanpd]j_en_haoknomq]nao
Pdaod]lak^fa_p_na]pa`eo6Wk^fa_pOp]nY
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:
Ep#oia(Omq]naPd]jgobkni]gejcia
Pdaod]lak^fa_p_na]pa`eo6Wk^fa_pOmq]naY
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.
 
Search Nedrilad ::




Custom Search