I don't see how you prevent the god object? You still need a way for a message to reach every object it may interact with. Either you need a god object that holds all other objects, like a phone book. Or you need coupling between objects, like a network. In the latter case, every object needs to store a pointer to every object it may want to interact with, which I think is a big mess.
Not at all, I quess it depends on the implementation, but basically my implementation works as follows. You have one "manager" that holds a list of all the entities:
class EntityManager
{
// methods for accessing entities based on their components, for adding and removing entities, ...
private:
std::vector<Entitiy*> m_vEntities;
}
This is not a god class. All it is, is basically a better std::vector with some convenience methods for entities creation, removal and access. The entity class itself stores a list of components:
class Entity
{
// methods for querying, adding and removing components:
private:
std::vector<Component*> m_vComponents;
}
Again, this is merely like a more intelligent vector, and not a god class at all. A component is derived from a base class, and represents plain, stupid data:
class Position : BaseComponent<Position>
{
math::Vector3 vPosition;
}
And then there is systems, implementing actual behaviour:
class TransformSystem final : System<TransformSystem>
{
// implements the logic for creating & updating the transform matrices of a bunch of entities
void Update(double dt) override;
void Register(MessageManager& messages) override;
void Receive(const BaseMessage& message) override;
}
And for each new feature, you just create two of the above, adding the system to a SystemManager (which is once again merely a more intelligent vector). Messages are passed via those systems, too, like in my original post. Each system has all the tools/classes available for dealing with the correct messages and manipulate its components based on it.
So there you go. Instead of a god-game-class that has all kind of methods (update-transform, update-physics, render), and a game-object god class with an equivalent to those, you now have single systems that work on their data and their data only. Do you see how this can break up the god-object now?