Entity Component System (ECS)
An Entity Component System (ECS) is an architectural pattern that is very popular in game development. This consist of entities that have components that systems perform operations on. This architectural pattern favor the principle of composition over inheritance. Each entity is not ruled by some hierarchy but instead is defined by its components. The systems will act on all entities that have the required components.
Entity
An entity is a generic object that usually consist of a unique id. For example, when creating a player the first thing we would do is create an entity called player with a unique id. At this point the player is just a unique id. We can not do anything with it yet.
Component
A component is a set of data that will be characterize the type of component it represents. For example, to give the player the ability to move we could create a transform component. This component would hold the players position on the screen and the velocity of the player. We would then go and add that component to the player entity. This component will not have any functions and will be purely data.
System
The system is a class of functions that can be performed on any entity with the required components. This is were the magic happens and we get to tell the game what to do with all this data we are storing. For example, the player has a transform component so we can create a movement system. This will require any entity that wants to use this system to have a transform component. The movement system could have a function that updates the position of the player to move them around the screen.
If we create an enemy and do not attach a transform component it will not be able to move around because the system can not perform any operations on it.
Summary
An entity is an object with a unique id that can not do anything by itself. To do something with that entity we have to give it bits of raw data that we pack together into components. We then perform operations on that data using the systems that we created.
ECS is a popular architectural pattern in game development due to its flexibility and maintainability. By favoring composition over inheritance, it allows developers to easily add or remove functionality and create complex game behaviors.