Game Development Reference
In-Depth Information
with a simple rule of thumb. Depending on the expectations of the users, it may
be an error case, or the runtime can choose the first value.
Sometimes when implementing a derived class, it is still important to refer to
the base implementation of a method. The same can be done for data inheritance;
instead of strictly overriding a value, a designer could add or subtract a constant
from the base value. By transforming the base value, incremental changes can be
made while keeping the advantages of data inheritance.
14.3 Constants
Another tool available in almost every programming language, which is so fun-
damental that we take it for granted, is named constants . By using constants,
programmers are able to talk about concepts, not specific unlabeled values. When
information is moved into data, we often lose this ability. Individual pieces of data
are often named, but it is often impossible to name individual pieces of data inside
an object.
14.3.1 Example
Continuing from the example above, a designer may be looking at the number of
hit points which different entities have:
<object name="Goblin" HitPoints="50" />
<object name="Goblin Knight" HitPoints="100"
/>
<object name="Goblin King" HitPoints="150"
/>
<object name="Kobold" HitPoints="50" />
<object name="Kobold King" HitPoints="150"
/>
<object name="Peasant" HitPoints="100"
/>
<object name="Knight" HitPoints="150"
/>
<object name="King" HitPoints="50" />
<object name="Dragon" HitPoints="1000"
/>
<object name="Lich" HitPoints="1000"
/>
There is not a large amount of variety in these data, but they are still quite
heterogeneous. In general, these objects are significantly different, so changing the
inheritance hierarchy would be quite detrimental to understanding the data. But,
at the same time, these values were all set for a reason. For the purpose of balancing,
it is very important to keep track of these values, and it is very intentional that the
same values repeat. If these data were all written in code, named constants would
be used to limit the amount of repeated data. Below, the data have been converted
to use named constants:
Search WWH ::




Custom Search