View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sum01 Final Exam Review: Message Lookup

When performing message lookup, some OO systems will consider the class of the arguments, and some will only consider the receiver of the message; this is called multiple-dispatch and single-dispatch, respectively. Give an advantage to each approach. Describe one problem that can be easily solved with multiple-dispatch, but which is much more complicated with single-dispatch.

I think the multiple-dispatch would be better at function overloading. A single-dispatch system would be much more difficult to find which particular version of the function to run.

(1) With static message lookup, methods are resolved at compile time. With dynamic message lookup, methods are resolved at runtime with the help of a method table and its offset computed at compile time.

C++ supports both static and dynamic method lookup. Methods need to be virtual for c++ to dynamically bind the method.

An obvious advantage with static lookup is speed. Most languages(Smalltalk) that support dynamic message lookup usually cache the last message sent which improves performance somewhat, but its still not comparable to static lookup. The advantage with dynamic message lookup is that your code can be more polymorphic(more reusable code).

(2) The advantage with multiple-dispatched messages is that you can resuse all the methods defined in your heirachy of inherited classes. The advantage with single-dispatched languages is that you can override inherited methods.

Could type checking be a problem easily solved with multiple-dispatch?

john borak

This (2) describes multiple inheritance, not multiple dispatch. Multiple-dispatch means checking multiple arguments to decide what method to execute. An example where this is useful is arithmetic: there are a zillion "add" commands floating around: integer+integer, float+float, integer+float, float+fraction, etc. Multiple dispatch is extremely helpful in making "x + y" invoke the right method. In a single-dispatch system, the "add" command often ends up calling other commands indirectly; it's complicated and it's a nuisance.

It might help with type checking, too, but you'd have to be more specific.

-Lex Spoon

Lauren Travis

Link to this Page