A light diversion: I was reflecting on the occasionally deep multiple inheritance objects in my WIP. I am honestly amazed how deep you can go without breaking things or creating conflicts, so figured I’d make it a contest. What is the deepest (meaning MOST) multiple inheritance objects/classes you have defined in a working game, ie one you have at least tested the first order behavior of? Sum of two scores: largest first level and largest total unique branches. I’ll start!
Total Score: 11. First level score: 5; Total Branch score: 6 (two branches for Chair: BasicChair and Surface, two for Vehicle: NestedRoom and Traveler, but NestedRoom redundant to BasicChair) Note first two are custom object Mixins.
Okay, I have at least one object whose superclass list has 10 elements, but it’s not that interesting when you realize it inherits from NorthItem, SouthItem, [six more DirectionItems], and two other classes. When I come across something a little more diverse, I’ll let you know…
Looks like there are 11 other objects besides the aforementioned that have 6 or more top-level class entries, but aside from the trashBarrel they all make multiple use of the DirItem theme…
Still getting my head around objects with 8 DirectionItems, yet don’t create coding conflicts. Even if all 8 Direction classes inherit from same branch, that’s a MINIMUM score of 13 (10 first level + 3 unique branches)! Contrasted to the 12+ of your barrel.
My sealed-envelope prediction was either you or @jbg FTW on this…
I would say “think of this as aspirational” but maybe flying this close to the sun is NOT such great advice…
I forget what it’s called, but I think my own coding has more often gone in the opposite direction, with one class containing several other classes as part of its data.
For example, for Micro Chao Garden, my attempt at a terminal game fan demake of the Chao Gardens from the Sonic Adventure games, my Chao class includes an instance of a separate breed class, an instance of a separate evolution class, and several instances of a separate stat class… and while chao.cpp has the highest line count of the 4 classes, it actually has the lowest word count and anyone who has dug into how those little critters works will know just how overengineered Chao are for what is presented as a small, side mini-game.
Actually, off top of my head, I’m not sure I’ve even used single inheritance outside of class assingments, though I would need to dig through all of my code to know for sure, and I’m not sure c++ supports multiple-inheritance…
The NorthItem etc. are just lightweight classes that give you some vocab and a couple of convenient strings. The vocab is ’north northern n -’ and it has adj = ‘northern’ and direc = ‘north’ properties that can be used by other code that is dealing generally with and printing text about collections of objects that could be from any which direction.
The main culprit that uses many (or even all) of the direction items at once is a Walls class of mine… you instantiate a Walls in a given Room, declare a list of enums specifying which directions possess a similar wall, and at preinit the instance adds to its own superclass list the direction items mentioned above that correspond to its enums. Just so you can easily customize the description of a location’s walls but still get the vocab pertaining to which walls you have and no more. If one wall needs a special object or a couple directions don’t have any walls that way, just declare your enum list appropriately and the Walls object will only respond to vocab in the directions where you’ve got “catchall” walls. It has some customized verb responses too.