5 ms·
Mattias Johansson uses basically this example in his argument for composition over inheritance. You have humans, robots, and dogs all fitting into your nice cla
by suzzer99 5y ago
Mattias Johansson uses basically this example in his argument for composition over inheritance. You have humans, robots, and dogs all fitting into your nice class hierarchy. But now you need a robot dog that breaks everything.
https://www.youtube.com/watch?v=wfMtDGfHWpA https://www.youtube.com/watch?v=wfMtDGfHWpA
I think inheritance makes the most sense when your problem domain has been known for decades - like airline reservations. But for new blue sky projects - you always seem to wind up in these snafus that break your rigid class hierarchy.
- breck 5y ago> You have humans, robots, and dogs all fitting into your nice class hierarchy. But now you need a robot dog that breaks everything. I like the way you put that. Though humans and dogs are 85% similar at a DNA level, so makes sense for them to inherit from a common parent. And my guess is robots and robot dogs would be ~85% similar at a building block level, so dog would inherit from robot. I think go easy on levels of inheritance but have really strong root classes that most things inherit from.
- suzzer99 5y agoHeh, I actually had that wrong. I probably should have watched the video instead of going by my recollection. He has a mix of robots and animals. Same concept.
- lupire 5y agoRobot dogs inherit from robot and dog. Mammalian dogs inherit from mammal and dog.
- suzzer99 5y agoIn a multiple inheritance world yes. But I think most C++ devs decides that led to a big mess in large systems. Supposedly one of the best things about Java was no multiple inheritance.
- pjmlp 5y agoExcept it happens that there are architecture scenarions where multiple inheritance makes sense, so all major languages have it in some form anyway. In what concerns Java you have multiple inheritance of interfaces, and as of Java 8, traits. Windows C++ frameworks, from Microsoft and Borland/Embarcadero make use of multiple inheritance.
- shagie 5y agoThe Codeless Code #83 - Consequences http://thecodelesscode.com/case/83 http://thecodelesscode.com/case/83 is a good read on that... or rather, its a spot to start thinking from. It ends with: > A nun of the temple whispered to Jinyu: “This problem has several solutions, but I dislike all of them.” > “Therein lies its value,” whispered the abbess in reply. “For we are all of us doomed in this profession: our designs may aspire to celestial purity, yet all requirements are born in the muck of a pig-sty. I trust that this monk can succeed when the stars align in his favor, but when they do not, how will he choose to fail? By cowardly surrender? By costly victory? By erroneous compromise? For it is not he alone but the temple that must bear the consequences.” There are also a set of "topics" hidden with a mouseover at the bottom that can waste a day away without difficulty.