Polymorphism is the advantage of OOP,but dots has no polymorphism. with the OOP, i can show different action for different person by a function. However, in the dots,if i want to show different action, i should code different system and attach different component.
Correct. With an ECS approach you tend to write more systems, but each is much smaller with a well-defined purpose.
This is also the primary way to re-use logic, when you combine multiple systems in new and interesting ways.
OOP:
class Animal {
}
class Cat : Animal {
}
class Dog : Animal {
}
ECS:
struct Animal : IComponentData {
}
struct Cat : IComponentData {
}
struct Dog : IComponentData {
}
// A cat entity
Entity cat = entityManager.CreateEntity(typeof(Animal), typeof(Cat));
// A dog entity
Entity dog = entityManager.CreateEntity(typeof(Animal), typeof(Dog));
// A system for Animals (base class)
class CommonAnimalStuffSystem : ComponentSystem {
}
// A system only for dogs
class DogStuffSystem : ComponentSystem {
}
// A system only for cats
class CatStuffSystem : ComponentSystem {
}
1 Like