Dynamic Dispatch

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

 

<< PreviousWord BrowserNext >>
meps for poland 2004 2009
tree of life foundation
pittodrie
the futureheads
meps for portugal 2004 2009
bureaucratic collectivism
meps for slovakia 2004 2009
academy of gundishapur
meps for slovenia 2004 2009
tannadice park
meps for spain 2004 2009
jij
meps for sweden 2004 2009
wing (comics)
baseball glove
inside the beltway
dens park
meps for ireland 2004 2009
toronto blessing
edward s. morse
pussy galore (band)
james dudley
winslow house
mark buckingham
touching evil
andrea doria class cruiser
vittorio veneto class cruiser
tag up
axopodium
mary noble
physicians' desk reference
azdavay
national library
szkesfehrvr
murray haszard
mid western highway
michael saso
mark millar
mcleod's daughters: songs from the series volume 2
loop line
list of state leaders in 1980
walther ppk
age of the universe
tommy tiernan