6 ms·
I've learned about multi-dispatch from Common Lisp, and back then was prototyping a turn-based game, where I can have multi-method working: Outcome attack(
by malkia 8y ago
I've learned about multi-dispatch from Common Lisp, and back then was prototyping a turn-based game, where I can have multi-method working:
Outcome attack( RangeBaseUnit attackingUnit, MeleeBasedUnit defendingUnit )
and also
Outcome attack( MeleeBasedUnit attackingUnit, RangeBasedUnit defendingUnit )
it was the most elegant approaches I've seen. Not that you can't do it in C++, but not as straightforward as it was in CLOS.
- zenexer 8y agoIn OOP, isn't that essentially just overloading? In many OO languages, you could write both of those lines as-is (with corresponding method bodies) and have valid code. They'll typically be treated as two separate methods that just happen to have the same name.
- oweiler 8y agoThe main difference is that overloading is resolved at compilation time whereas multi methods are resolved at runtime.
- pjmlp 8y agoNo because multi-mthods don't have a self/this pointer as such, rather they are dispatched at runtime taking into account the actual types of each parameter.
- skocznymroczny 8y agoIn OOP, I think the closest equivalent would be the visitor pattern.