Every example I've seen on the subject suggests that composition is emulating an inheritance model.
What do you mean? Can you provide a link to one of these examples?
I'm not sure what you mean about composition emulating inheritance, but composition is typically thought of as being an
alternative to inheritance, not an emulation of it. Composition has different characteristics than inheritance, and addresses some of the issues that often crop up with the latter technique. In particular, composition offers greater orthogonality, which is one of the characteristics component-based systems exploit.
Can you clarify what you mean about composition emulating inheritance?
The TransformComponent would actually be called MovableEntity (or some other). It is then fair to say that a CollidableEntity 'is a' MovableEntity which is then the base class for any CollidableEntities.[/quote]
How about a tree? It's a collidable entity, but not a moveable entity (most likely). How would that fit into the inheritance hierarchy you describe?
The inheritance method does exactly this although it enforces any dependencies at compile time rather than at runtime. In the example above if one of your entities had a CollidableComponent but never had a TransformComponent then your program would crash.[/quote]
Component-based systems usually have mechanisms in place to ensure dependencies are present. In a language that supports exceptions, for example, you might simply throw an exception if a required component is missing. Another option is to add any required components automatically if they haven't been specified explicitly.
As for the fact that missing dependencies are detected at run time rather than compile time, that shouldn't be an issue. In a data-driven component-based system, entity definitions are data, just like models, textures, sounds, and game levels (this is one of the strengths of the system). It'll pretty much always be the case that a shipped game will rely on the accompanying data being correct and internally consistent. You wouldn't ship a game with a level with no spawn point, or a material that referenced a non-existent texture, or a sound file in an unreadable format, or anything like that. Ensuring that entity definitions include all the required components is no different; it's just part of ensuring that the game data is integral and internally consistent.
In other words, identifying missing component dependencies at run time is perfectly normal and is in keeping with how game data is handled in general.
But every entity needs it own unique functionality, for e.g. if you attach a health component to some entity in your game it wont really do much other than take damage etc. You need some code somewhere that makes this data meaningful e.g. code that says: "if health < 0 then set object state to dead and set position to (x,y,z)". So in a component-based system where do you put this code?[/quote]
It depends. It could go in the 'health' component if that behavior is common to all entities with health, or it could go in another component whose only responsibility is tracking the health and taking the appropriate action when it reaches some threshold, or it could go in a collision callback function, or it could go in a component associated with a 'mediator' entity that has knowledge of all entities with health, etc. There's really no one right answer to the question.
It's clear you're not sold on component-based systems, and no one's saying you have to be :) But, component-based systems work just fine.
If a concrete example would help, you might download the Unity engine and play around with it a little (it uses a 100% component-based entity system).