Dynamic_dispatch Dynamic_dispatch

Dynamic dispatch - Definition and Overview

Related Words: Account, Acknowledgment, Acquaintance, Address, Administration, Advice, Agility, Airmail, Annihilate, Announcement, Answer, Assassinate, Assassination, Bane, Billet

In computer science, dynamic dispatch is the process of mapping a method call to a specific sequence of code at runtime (i.e. dynamically), often in cases where the appropriate method cannot be determined at compile-time (i.e. statically). It is used in object-oriented programming to allow polymorphism.

Dynamic dispatch is performed when multiple classes contain different implementations of the same method foo(). If the type of an object x is not known at compile-time, then when x.foo() is called, the program must decide at runtime which implementation of foo() to invoke, based on the runtime type of object x. This case is known as single dispatch because an implementation is chosen based on a single type--that of the this or self object. Single dispatch is supported by many object-oriented languages, including strongly-typed languages such as C++ and Java, and weakly-typed languages such as Smalltalk and Objective-C.

In a small number of languages such as Common Lisp, methods or functions can also be dynamically dispatched based on the type of arguments. Expressed in pseudocode, the code manager.handle(y) could call different implementations depending on the type of object y. This is known as multiple dispatch.

C++ Implementation

Dynamic dispatch incurs some computational overhead at runtime: when a method is called, a virtual function table or dictionary of methods must be referenced to find the memory address of the appropriate implementation. For this reason, Bjarne Stroustrup, the designer of C++, elected to make dynamic dispatch optional and non-default. Only functions declared with the virtual keyword will be dispatched based on the runtime type of the object; other functions will be dispatched based on the object's static type.

See also

Example Usage of dispatch

Dailymailnews: A very merry Christmas: Europe's largest wine warehouse prepares to dispatch 36 million bottles for the festive sea... http://bit.ly/8Sw347
brandonpierce: @JeffHarbert I tried to phone in a dispatch - line was busy - apparently there are a lot of calls in right now for caffeine... Over.
imadnaffa: HOK firm founder, Gyo Obata, featured in the Post dispatch: http://is.gd/57O8D #STL #architect /via @threefourteen #architecture
Copyright 2009 WordIQ.com - Privacy Policy  :: Terms of Use  :: Contact Us  :: About Us
This article is licensed under the GNU Free Documentation License. It uses material from the this Wikipedia article.