4 ms·
> What does the non-OOP solution for this problem look like? function hit(player, weapon, monster) { This is a major problem with single dispatch, a popul
by geocar 8y ago
> What does the non-OOP solution for this problem look like?
function hit(player, weapon, monster) {
This is a major problem with single dispatch, a popular OOP implementation choice, but not the only one. Common Lisp and C++ have multiple dispatch, which is a generally accepted solution to this problem.
It seems like a lot of the challenges you're facing has to do with object-oriented design not being a good fit for your problem. Some problems really do organise well into independent actors, maybe the one you're doing isn't one of them?
- vnorilo 8y agoI don't think C++ has a dynamic multiple dispatch mechanism. You can craft one with the visitor pattern or some precompiling or macro sheanigans. I'd love to hear about the best way of doing it.
- geocar 8y agoNo. Not dynamic. The best way is to use Common Lisp. I don't know if there's consensus for other, lesser solutions. Stroustrup seems to think C++ just isn't good enough[1], but good ol' function overloading is good enough for the cases we're discussing. [1]: http://www.stroustrup.com/multimethods.pdf http://www.stroustrup.com/multimethods.pdf