2 ms·
Ok nice, then you get a huge if tree for all different monsters and weapons.
by jbverschoor 8y ago
Ok nice, then you get a huge if tree for all different monsters and weapons.
- ubercow13 8y agoHow's that any different to a 'classical OOP' approach?
- wffurr 8y agoYou can have free functions that operate on your classes instead of shoehorning every operation into one class or another or creating new ones from whole cloth just to hold a function (e.g. the Hit class mentioned earlier). Writing methods makes it easy to add new types but not methods; you have to change every class to implement a new method. Writing functions makes it easy to add new function, but you have to update every function for a new type. Each has its place, and issues arise when certain languages (e.g. Java) or paradigms ("classical" OOP) make it impossible to use one or the other style.
- ced 8y agoWhat do you mean? It wouldn't be "if". You'd just have function hit(p::Player, m::Goblin) ... end function hit(p::Player, o::Ogre) ... end In Julia, there's limited inheritance, so you could group monsters in a hierarchy to limit the redundancy (eg. Goblin <: Monster <: Creature). Or you can use multiple dispatch like a trait system, to get even greater flexibility.