5 ms·
That's very interesting, because I had observed exactly the same when I tried to implement a rogue-like in Java some years ago. For example, I had to decide whe
by tralarpa 5y ago
That's very interesting, because I had observed exactly the same when I tried to implement a rogue-like in Java some years ago. For example, I had to decide whether there should be different subclasses for spell books, the different weapon types (e.g bows vs swords), drinks, etc. or just one big Item class. Closely related to that, another decision I had to make was whether object or character properties should be implemented as class members or as entries in a hashmap (where the latter is a class member). At the end, I had the feeling that I was implementing my own class/object system on top of Java's one. I guess in other languages, like lisp, this is not really an issue.
IIRC I already wrote that here on HN, but I think implementing a simple rogue-like is an excellent exercise to get familiar with any programming language.
- suzzer99 5y agoMattias 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.
- Gene_Parmesan 5y agoDefinitely components are the way to go. These have gotten very well known recently in the game dev world thanks to entity component systems, which is what I would call "heavy components," but you can also do "light components." Meaning, you don't need to organize your entire system around an ECS in order to take advantage of some of their benefits. They make changing behavior dynamically extremely simple. Instead of needing to hardcode classes for each different type of thing players may want to create in your world, you just assign and unassign components. Give a rock the Moveable component and now it moves. Remove the PlayerControl component from the player and put it on, I don't know, an orc -- now you've implemented body swapping. They're even more useful in a game like traditional roguelikes, where you don't have to worry about animating all these dynamic states. I've actually never thought about how a component system might fit into a more traditional business application; it's an interesting thought experiment but I'm not quite sure it would be a strong benefit.
- dgb23 5y agoDatabase modeling comes to mind, especially EAV.