Описание тега dynamic-dispatch
In /questions/tagged/computer-science, dynamic dispatch is the process of selecting which implementation of a polymorphic operation ( method or function) to call at runtime.
Dynamic dispatch contrasts with static dispatch in which the implementation of a polymorphic operation is selected at compile-time. The purpose of dynamic dispatch is to support cases where the appropriate implementation of a polymorphic operation can't be determined at compile time because it depends on the runtime type of one or more actual parameters to the operation.
Dynamic dispatch is different from /questions/tagged/dynamic-binding or late-binding. In the context of selecting an operation, binding refers to the process of associating a name with an operation.
Dispatching refers to choosing an implementation for the operation after you have decided which operation a name refers to.
With dynamic dispatch, the name may be bound to a polymorphic operation at compile time, but the implementation not be chosen until runtime (this is how dynamic dispatch works in C++). However, late binding does imply dynamic dispatching since you cannot choose which implementation of a polymorphic operation to select until you have selected the operation that the name refers to.
Dynamic dispatch is often used in /questions/tagged/object-oriented languages when different classes contain different implementations of the same method due to common inheritance. For example, suppose you have classes A, B, and C, where B and C both inherit the method foo() from A. Now suppose x is variable of class A. At run time, x may actually have a value of type B or C and in general you can't know what it is at compile time.
With static dispatch, a method-call x.foo() will always refer to the implementation of foo() for class A because static binding only looks at the declared type of the object. With dynamic dispatch the language will determine the type of the value of x at run-time and call the version of foo() that is associated with whatever type the value has, whether A, B, or C.