(I asked a similar question, but it had more questions inside it and I feel it wasn't clear enough, so I'm opening a new one).

Until recently I implemented all my games using an inheritance hierarchy. Those were simple games.

For example:

          /    \
      Movable  Static
      /  \        /  \
    Orc  Mage   Tree  Wall

This worked for simple games.

However recently I read about 'entity component systems'. Using this approach, a class doesn't inherit from another class in order to receive functionality. Instead it is composed with it, which allows for more flexible designs.

My question is this:

I know that each component is a class (derived from a common base class).

However, there is one thing I don't understand: In the 'component system' approach, is there one class that all entities are instances of - and the only difference between entities is the components they contain?

For example: There is a class Entity. All entities in the game are instances of this class.

The only differences between them is that they are composed with different Component objects.

For example:

Component aiComponent = new AIComponent();
Component movementComponent = new MovementComponent();
Component physicsComponent = new PhysicsComponent();
Component rangedAttackComponent = new RangedAttackComponent();

Entity orc = new Entity();

Entity shootingCastle = new Entity();

As you can see, both orc and shootingCastle are instances of the Entity class. But they are composed with different components.

Is this how 'entity component systems' are supposed to be? No inheritance hierarchy at all? Or is there still a basic inheritance hierarchy, but most of the logic is inside components?

  • \$\begingroup\$ This doesn't look significantly different from your first question to me. The answers would certainly be essentially the same ("it depends"). \$\endgroup\$
    – user1430
    Commented Apr 22, 2014 at 15:15
  • \$\begingroup\$ It does seem you put more thought into this question though. I would reccomend updating the first one since it seems you have narrowed your focus. \$\endgroup\$ Commented Apr 22, 2014 at 15:35
  • \$\begingroup\$ I'm working on my own, ECS right now. I can state that I'll be using some hierarchy to generate a default (entity/component/attribute) class that is expanded later to form a more specific type. This will let my systems look for either a generic class, or a more specific one when they do their processing later. \$\endgroup\$
    – user44880
    Commented Apr 22, 2014 at 16:38


Browse other questions tagged .