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, single and/or multiple:
“I have simplified my politics into an utter detestation of all existing governments; and, as it is the shortest and most agreeable and summary feeling imaginable, the first moment of an universal republic would convert me into an advocate for single and uncontradicted despotism. The fact is, riches are power, and poverty is slavery all over the earth, and one sort of establishment is no better, nor worse, for a people than another.”
—George Gordon Noel Byron (17881824)
“Sheriff, have you ever watched a friend dying before your eyes and not been able to help? Thats the worst of it. Being helpless. Its particularly tough when youre a physician and you know whats wrong with him, and there isnt a single solitary thing you or anyone else can do.”
—Robert M. Fresco. Jack Arnold. Prof. Gerald Deemer (Leo G. Carroll)
“... the generation of the 20s was truly secular in that it still knew its theology and its varieties of religious experience. We are post-secular, inventing new faiths, without any sense of organizing truths. The truths we accept are so multiple that honesty becomes little more than a strategy by which you manage your tendencies toward duplicity.”
—Ann Douglas (b. 1942)