Game Development Reference
In-Depth Information
industry work extremely well for applications that perform specific
tasks, such as productivity apps, utilities, design software, and so on.
However, design patterns aren
t always the answer for game devel-
opment, because games are meant to feel more like
'
than rigid, predictable business software. The best solution to
develop a game engine may not follow an
experiences
accepted
pattern at all,
and that
s perfectly okay. However, some basic principles should be
followed when using OOP so that your code is modular and scalable.
'
Encapsulation
One of the most fundamental OOP concepts is encapsulation.
Briefly, encapsulation is the notion that an object (or class, in
ActionScript) should be entirely self-managed and contained.
An object should not have to know anything about the environment
in which it exists to carry out its functions, and it should have a pre-
scribed list of functions (or interface) that other objects can use to
tell it what to do. In order to send information to objects outside, it
should send messages that can be
by other objects.
You can think of a well-encapsulated object like a soda vending
machine. All of the inner workings are hidden away from you, and
its functionality is distilled down to the buttons you can press to
select a drink and the bin in which you can
listened to
to receive your
purchase. There is no reason for you to know what is going on
inside the machine; it might be a couple of gnomes brewing and
canning the soda right there on the spot or it might just be a series
of tubes. Either way, all you
listen
re interested in is getting your tasty
sugar water through an interface that is easy to understand and
use. If you look at any of the built-in classes in Flash, they follow
this same pattern. The only information listed about a class in the
documentation is its public methods, properties, and events. There
is certainly more going on
'
under the hood
than what we
'
re
exposed to, but we don
t need to know about all of it. Your goal
should be the same in developing your classes for games.
'
Inheritance
Say we have two classes, Chair and Sofa. Each of these classes
share similar traits such as weight, size, number of legs, number of
people they can seat, and so on because they both are types of sit-
ting furniture. Instead of defining all of these traits in both classes,
we could save ourselves time by creating a class called Furniture
and adding the common traits to those. We could then say that
Chair and Sofa inherit those properties by being (or extending)
Furniture. This is the concept of inheritance; all objects in the real
and virtual worlds have a hierarchy. When programming in an
object-oriented style, the key to maximizing efficiency is to recognize
Search Nedrilad ::




Custom Search