Brief introduction to ECS (from Wikipedia):
- Entity: An entity represents a general-purpose object. In a game engine context, for example, every coarse game object is represented as an entity. Usually, it only consists of a unique id. Implementations typically use a plain integer for this.[3]
- Component: A component characterizes an entity as possessing a particular aspect, and holds the data needed to model that aspect. For example, every game object that can take damage might have a Health component associated with its entity. Implementations typically use structs, classes, or associative arrays.[3]
- System: A system is a process which acts on all entities with the desired components. For example, a physics system may query for entities having mass, velocity and position components, and iterate over the results doing physics calculations on the set of components for each entity.
Similarities I've observed:
1. Separation of Concerns:
- ECS separates components (Data) from systems (Behavior).
- DCI separates what the system is (Data) from what it does (Interactions).
2. Runtime Object Composition:
- ECS allows for dynamic composition of entities with different components.
- DCI enables objects to take on different roles in various contexts at runtime.
3. Behavior Externalization:
- ECS places behavior in Systems, external to the data (Components).
- DCI places behavior in Interactions, separate from the core Data.
4. Context-Dependent Behavior:
- In ECS, Systems operate on entities with specific component combinations.
- In DCI, data assume roles with specific behaviors in different contexts.
5. Flexibility and Modularity:
- Both patterns aim to create more flexible and modular systems.
Potential Correspondences:
- ECS Entity + Component ≈ DCI Data
- ECS System ≈ DCI Context + Interaction
Key Differences:
- ECS has more rigid structures (Entity as unique ID, Systems acting on all matching entities).
- DCI focuses more on roles and context, while ECS emphasizes component-based composition.
Could ECS be viewed as a specific implementation or variation of DCI principles?