4 ms·
Sorry to continue, but could you elaborate on that? I understand both concepts, but not their relative merits...
by veddox 8y ago
Sorry to continue, but could you elaborate on that? I understand both concepts, but not their relative merits...
- pjmlp 8y agoInstance methods are bound to a specific object definition, thus they can only be applied to instances of that specific object or its descendants. Also in static languages, the set of available instance is closed and extending it requires approaches like extension methods now available in a couple of OOP languages. Whereas multi-methods are dynamically dispatched taking into consideration the whole set of parameters, and can be defined after the fact. Meaning that they aren't necessarily written in the same module that defines the respective data structures, which opens the door to more extensible designs. Taking the Alan Perlis' quote "It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures." to the next level. Because not only can you define all those functions that operate on one data structure, they actually apply to the tuple made by the dynamic type of all parameters at call site. Naturally it also might make it harder to follow what actually happens with a given method dispatch. This is my insight from having gone through "The Art of the Metaobject Protocol" and dabbling with multi-methods in Clojure, so I might not be 100% correct here.