4 ms·
IMHO inheritance works and only works for graphics related programming, e.g. GUI and games. Visual objects can be abstracted in the manner of inheritance.
by est 3y ago
IMHO inheritance works and only works for graphics related programming, e.g. GUI and games. Visual objects can be abstracted in the manner of inheritance.
- mattnewport 3y agoInheritance doesn't work well for games, that's why so many games take a component based approach like Unity, or full blown ECS.
- lewispollard 3y agoWell, it does work well for the engine part of game engines, and graphics related code in particular as the GP says - it's just gameplay code where OO falls a bit flat.
- ipaddr 3y agoUnless it'a role playing game.
- lewispollard 3y agoI don't follow - role playing games are often most suited to ECS, because you want the kind of emergent gameplay that independent gameplay systems acting on component composition gives you - and the kind of flexibility it allows in composing weapons, spells, buffs/debuffs, and so on, vs a strictly hierarchical OOP approach.
- mattnewport 3y agoNot really, the data oriented design movement in games programming that eschews OOP is driven by performance concerns of traditional OOP code on areas like rendering. As a graphics programmer for many years I can also say that OOP is not really a good fit design wise for modern rendering engines, it mostly just gets in the way.
- lewispollard 3y agoI only really know of Bevy that uses ECS for the rendering backend, but iirc even that doesn't really use entities and components, but rather its resource system, such that rendering commands are stored in the ECS "world" but as globally unique resources, rather than entities and components. But, my knowledge doesn't extend to AAA engines, perhaps things are done more extensively there.
- professoretc 3y agoThe implementation of inheritance (more specifically, polymorphism and dynamic dispatch via vtables) is a problem in games, because it adds an extra layer of indirection, and screws with cache locality. But the semantics of inheritance (X ISA Y) still apply. In an ECS, the implementation is different (struct-of-arrays) but you can still think of an entity as "inheriting from" the various components its built from.
- tubthumper8 3y ago> you can still think of an entity as "inheriting from" the various components its built from. If it's based on components, wouldn't that mean you would think of it as being... _composed_? I typically don't hear "it's made of many components" and think of inheritance
- mattnewport 3y agoThat's not really accurate. Component based systems are designed specifically to address situations that traditional inheritance doesn't handle well. Examples are usually something like having a base entity, a player that inherits from entity and an enemy that inherits from entity. Then you have a magic user and a barbarian inherit from enemy but now you also want your player to be able to use magic. Traditional OOP doesn't make it easy to share the implementation. Even with composition and interfaces you still have problems with most traditional OOP languages when you want to do things like change the set of components of an entity dynamically at runtime (player gains or loses the ability to use magic during the game). "Is a" is often not the relationship you want to model. A player and an NPC both have the "has a" relationship to an inventory, not the "is a" for example.
- fxd123 3y agoThat's strange because I was about to comment the exact opposite. ECS is for games, inheritance is for almost everything else
- ipaddr 3y agoFor games having your character as a type of a general class fits well. Having enemies be a type of a class with a base of abilities can fit well too. Weapons, etc all module well. Game play. Scenes.
- davedx 3y agoThis has more or less been my experience too. Things like UI toolkits or game engine primitives are often solved nicely with inheritance. I've been doing a lot with LeafletJS lately, and it has some light inheritance around its drawing primitives (things like boxes, circles and lines you draw on top of maps). It works well. For 3D engines you still need to be quite careful with where you apply it though. It's possible to get into a huge mess if you use it too much.
- flohofwoe 3y agoEspecially in games, inheritance doesn't work all that great and had been replaced by composition via components a long time ago where each component implements one specific aspect or feature of a game object and can be (more or less) freely combined with other components.
- KevinMS 3y agoand it became popular at just about the same time as GUI programming, coincidence?
- cess11 3y agoThe picolisp database convinced me that it also can work for databases, where it's used both for data storage, querying and as a GUI backend.