4 ms·
OOP classes are commonly used because they seem to naturally map to physical objects, especially in games. However they can break down when trying to model the
by Leftium 3y ago
OOP classes are commonly used because they seem to naturally map to physical objects, especially in games. However they can break down when trying to model the inevitable exceptions to this "natural" mapping or abstract concepts.
OOP is based on inheritance, but there is a school of thought that prefers composition over inheritance[1]. Composition is more flexible and usually more CPU cache efficient. Entity component system (ECS) is another way to store game objects based on composition. Instead of grouping properties related to a single object together, the same property from all objects are grouped together (thus it is usually more CPU cache efficient).
Someone made the argument the logical conclusion of ECS is a relational database: store and modify your (game) entities using SQL![2]
Another paradigm is using immutable state (works with either OOP-like objects or ECS-like entities). CRUD loses data that event-sourced objects can access later. (CRUD cannot remember what items were removed from a shopping cart without extra work; event-sourced objects naturally retain this information.)[3]
[1]: https://youtu.be/hxGOiiR9ZKg https://youtu.be/hxGOiiR9ZKg
[2]: https://hw.leftium.com/#/item/38545417 https://hw.leftium.com/#/item/38545417
[3]: https://youtu.be/I3uH3iiiDqY https://youtu.be/I3uH3iiiDqY