Double dispatch

Chris Grindstaff ChrisG at appliedreasoning.com
Wed Nov 4 15:35:45 UTC 1998


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
Jim Menard wrote:

> Gang,
>
> I've seen quite a few references to double dispatching. What is that?
> URL's, pointers to docs, or a simple RTFM (but *which* FM) would be
> appreciated.
>
> Jim
> --
> Jim Menard   jimm at io.com   http://www.io.com/~jimm/   BeOS developer #1283
> "An object at rest cannot be stopped!"
>     -- The Evil Midnight Bomber What Bombs At Midnight

--
------------------------------------
Chris Grindstaff - Applied Reasoning
mailto:chrisg at appliedreasoning.com
http://www.appliedreasoning.com
919-851-7677





More information about the Squeak-dev mailing list