Message-ID: <844097423.669.1369185010265.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_668_731551614.1369185010264" ------=_Part_668_731551614.1369185010264 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
These examples demonstrate the use of duck typing to implement <= a href=3D"http://en.wikipedia.org/wiki/Multimethods" class=3D"external-link= " rel=3D"nofollow">multimethods (also called m= ultiple dispatch). With multimethods, the decision about which method = to call is deferred until runtime based on the actual runtime types of the = arguments to the method. The Dylan and Nice programming languages implemen= t it by default, boo lets the programmer decide when to use it via duck typ= ing.
Multimethods are useful when the correct method to call cannot be determ= ined at compile time because the runtime argument types are not known. Two= examples are shown - multiple dispatch of static methods and multiple disp= atch of instance methods.
The inspiration for the first example was taken from = Visitor Pattern Versus Multimethods and demonstrates multiple dispatch = of a static class method.
The next example shows how a class which collects integers (IntCollector= ) can be extended with minimal effort to sift through lists too (MyListIntC= ollector) and demonstrates multiple dispatch of an instance method.
The output of s.dump() is:------=_Part_668_731551614.1369185010264--