Entity–component–system (ECS) is an architectural pattern that is mostly used in game development. ECS follows the composition over inheritance principle that allows greater flexibility in defining entities where every object in a game's scene is an entity (e.g. enemies, bullets, vehicles, etc.). Every entity consists of one or more components which add behavior or functionality. Therefore, the behavior of an entity can be changed at runtime by adding or removing components. This eliminates the ambiguity problems of deep and wide inheritance hierarchies that are difficult to understand, maintain and extend. Common ECS approaches are highly compatible and often combined with data-oriented design techniques.
Architecture contains three different classes: Entity, System and Component.
Entity: The entity is a general purpose object. Typically Entity has several components attached to it. If several components are attached to Entity, it will result to some object type. See Entity diagrams below for examples.
Component: the raw data for one aspect of the object, and how it interacts with the world. Labels the Entity as possessing this particular aspect. Implementations typically use structs, classes, or associative arrays.
System: Each System runs continuously (as though each System had its own private thread) and performs global actions on every Entity that possesses a Component of the same aspect as that System.
Animal System is a kind of system, which has Animal Behaviour -components. There are several kind of AnimalBehaviours like: Flight, Pack and Walk behaviours.
You can find some kind of reference implementation of ECS in repository: ´https://repo.kamit.fi/mikkorom_examples/naive_ecs.git´
git clone https://repo.kamit.fi/mikkorom_examples/naive_ecs.git