Dynamic Dispatch - Single and Multiple Dispatch

Single and Multiple Dispatch

Dynamic dispatch is needed when multiple classes contain different implementations of the same method (for example foo). If the class 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 type of the instance. Single dispatch is supported by many object-oriented languages, including statically typed languages such as C++ and Java, and dynamically typed languages such as Smalltalk and Objective-C.

In a small number of languages such as Common Lisp and Dylan, 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.

Read more about this topic:  Dynamic Dispatch

Famous quotes containing the words single and/or multiple:

    Anyone with a real taste for solitude who indulges that taste encounters the dangers of any other drug-taker. The habit grows. You become an addict.... Absorbed in the visions of solitude, human beings are only interruptions. What voice can equal the voices of solitude? What sights equal the movement of a single day’s tide of light across the floor boards of one room? What drama be as continuously absorbing as the interior one?
    Jessamyn West (1902–1984)

    There is a continual exchange of ideas between all minds of a generation. Journalists, popular novelists, illustrators, and cartoonists adapt the truths discovered by the powerful intellects for the multitude. It is like a spiritual flood, like a gush that pours into multiple cascades until it forms the great moving sheet of water that stands for the mentality of a period.
    Auguste Rodin (1849–1917)