Today I read about PushButton Engine, which is an open source Flash-based game engine (if you want to discuss it, please start a new thread). What interested me was the idea of Components, which, as far as I can tell, have only really been discussed here.
Component-driven design is an alternative to inheritance-driven design. Both designs are object oriented, but with components, all game objects are formless entities with no properties of their own. The game developer can take these entities and apply components to them. Each component adds a set of properties and behaviors to the entity, and can interact with other components that have been applied. By selecting which components are applied to each entity and by adjusting the properties, you add form to the entity. To accomplish this, you can use templates to provide a default set of components and properties to apply to entities. Templates can specialize one another in a traditional inheritance pattern, and then an entity is an instantiation of a particular template.
Before I clarify this, let me show the example that the slides use. Slide 27 shows a subset of the template forest. On the left is a list of root templates, or those that don't specialize any others. The slide shows a list of specialized templates descending in a hierarchy to an example chicken template. Slide 28 shows the details of a template, including how it defines values for the properties. On slide 33, we see the chicken instantiated with a few instance-specific property values specified.
To reiterate, components define what properties exist, but set no values for them. Templates are parallel to the inheritance pattern's classes, in that they specialize one another in a hierarchy. Templates may set or change values for properties but are not required to. Finally, a template can be instantiated. Instances may additionally change the values for properties.
This concept for structuring wildly different types of objects is interesting to me. It's really only a small modification to the inheritance pattern. What are your thoughts/opinions?
- I am referring to the GDC 2002 paper. For your convenience, I have attached a PDF version of the slides. Note: the HTML version of the slides doesn't appear to work.