I've recently discovered the Entity Component System (ECS) and indeed, it seems to be a good design pattern for games.
My game is still pretty small, but there is already a great number of classes. That's why I'm planning on refactoring my whole code to implement an ECS.
I've read several articles and tutorials about ECS, I think I have a good overall comprehension of the pattern, but I have some questions about the implementation.
This is how I see it:
- An abstract class (interface) Component from which all components inherit from.
- An Entity class. Each instance stores an array of Components*. Components can be added to an entity through the addComponent(Component*) method. This method also attaches the entity to the right systems (e.g. if we add the component Position, the entity is attached to the system MoveSystem).
- An abstract class System from which all systems inherit from. As described above, each system keeps an array of the entities it should work on. Finally, each system has an update() method to update the entities.
So far, is it correct?
Ok, so I wonder how I should implement the systems. Since there is no reason to instanciate them (it would make no sense), the methods should be static, don't you think? Or better, I could use a singleton to make sure there is only one instance of each system.
What do you think?