Game Development Reference
In-Depth Information
structures can
down to subclasses and create problems
wherenoneexistedbefore.Thisiswhereinterfacescomeinvery
handy.
For these three classes, you can simply define distinct interfaces
that support each one
ripple
'
s specific needs. You could break down the
interfaces as such:
￿
IFurniture: contains move() method
￿
ISeatedFurniture: contains sitDown() method
￿ ILayingFurniture: contains layDown() method
￿ ITableFurniture: contains setDishes() method
Unlike inheritance, where a class can only inherit directly from
one other class, you can use, however, many interfaces you like
with a single class. The Chair would implement IFurniture and
ISeatedFurniture. The Sofa would contain those two, as well as
ILayingFurniture, and the Table would contain IFurniture and ITa-
bleFurniture. Also, because interfaces can extend one another, the
latter three interfaces could all extend the first one as well, making
implementation even simpler. Now that you have some basic inter-
faces defined for different furniture purposes, you can mix and
match them as needed to apply to a particular piece of furniture.
Don
t worry if some of this abstract terminology gets confusing.
When we build a full-scale game in Chapter 14, you
'
'
ll be able to
see these concepts in practice.
Practical OOP in Game Development
By default, AS3 supports OOP and good encapsulation through the
use of events to send messages between objects. I
s
event model described as being akin to the Observer design pattern,
but regardless of the niche it falls into, it is the native way in which
the language operates. Remember that despite the advantages
other patterns may offer, all of them are altering the default beha-
vior of the language if they deviate from this model. Figure 5.1
shows the relationship of objects to each other in AS3
'
ve heard AS3
'
'
s hierarchy.
Dispatch bubbling
events*
Dispatch events
Dispatch events
Object1
(root
level)
Object2
Object3
Figure 5.1 The basic event
and communication model for
AS3.
Eventdispatcher/display list* hierarchy
Search Nedrilad ::




Custom Search