Game Development Reference
In-Depth Information
// Iterate through all of the input objects
foreach(node : InputObjects)
{
// Find the "base" node for this piece of data
baseNode = GetObjectWithName(node["@Base"]);
if (baseNode != null)
{
// Iterate through the attributes of the base
foreach (field : baseNode.Fields)
{
// If this field is in the parent but
// not the child, copy the value
if (node[field.Name] == null)
{
node[field.Name] = field.Value;
}
}
}
}
14.2.3 Complications
The act of data inheritance is quite simple, but much like poorly designed code,
inheritance can lead to problems, as can poorly designed data inheritance. Just
because two pieces of data share the same fields, it does not mean that there should
be an inheritance relationship between the two. Inheritance is an implicit contract
that two are related: one is a specialized version of the other.
Additionally, from an implementation point of view, data inheritance adds a
significant amount of work to the build system. Dependencies must be strictly
obeyed with inheritance. Much like a header file that defines a class, all inherited
data that depend on a piece of base data will need to be reconditioned (compiled)
when that base data changes. Children will have to be recursively reconditioned.
Without careful thought about the inheritance of data, this can lead to significant
build time issues. A small tweak to an object may have larger repercussions if it is
the base of a tall inheritance tree.
14.2.4 Additions
Inheritance is only the first possible step toward more expressive object layout.
Building off of the parallels of object-oriented programming, other concepts can
follow just as cleanly. Multiple inheritance is sometimes used to combine different
inheritance trees together, and the same can be used for combining different trees
of data into one composite piece of data. Instead of setting an individual base data,
multiple base data can be conglomerated together. Much like object inheritance,
multiple data inheritance comes with its own set of problems. For example, if two
base objects define the same field, the child classes will need to properly handle
these conflicts. Resolving these and other issues is merely a matter of coming up
Search WWH ::




Custom Search