Double dispatch

L. M. Rappaport rapp at lmr.com
Wed Nov 4 21:56:48 UTC 1998


On Wed, 04 Nov 1998 10:35:45 -0500, you wrote (with possible editing):

>Jim,
>    In short double dispatching is a "typed" message send.  Probably the
>classic example is implementing arithmetic.  (Squeak doesn't use DD at the
>moment although several folks have changed it to)  Let's take Integer>>#+ as
>an example.  The #+ method accepts one argument.  How would we code the #+
>method so it works nicely with magnitudes we haven't conceived of?  Of course
>one approach would be to place a switch-like statement in the method, but
>there are maintenance problems with that solution.  The double-dispatch way
>advocates turning around and sending a message to the argument.  However the
>message you send to the argument is what I called a "typed" message; meaning
>it conveys something about the receiver.  For example:
>#+ aNumber
>    aNumber addToInteger: self.
>
>The "typed" message send obviously comes in to play with the "..ToInteger"
>part.  The advantage of this is that new classes of objects can be created
>that can be dropped into the current system without too much work.  You would
>have to implement all of the typed message sends in your new class that
>describe how the new class adds, subtracts, etc. to integers, floats,
>complexes, etc.
>
>HTH,
>chris

Chris, 

	That's great explanation - certainly straightened me out!   I'd
just add for Jim's benefit that the reasoning here is that using
double dispatch this way elegantly handles the scenario of "I don't
know what type _YOU_ are but I know what type _I_ am so YOU do this
using the method addToInteger with _ME_ as the argument.  The upside
is that it's fast.  The downside is that you have to implement the
method in all possible receivers.

	Thanks,


Larry
--
rapp at lmr.com





More information about the Squeak-dev mailing list