Learning path

Full curriculum

Full curriculum

Arrows go from each prerequisite to the units that depend on it. Hover or focus a unit to highlight its path.

Unit content

Dynamic dispatch and method lookup

When several concrete object types implement the same operation, a language may choose the method implementation at runtime according to the receiver's dynamic type. This is dynamic dispatch.

Suppose a variable has static interface type Shape but currently refers to a Circle:

Shape s = Circle(2)
s.area()

The call must invoke Circle.area, not a generic implementation chosen only from the variable's static type.

A common implementation assigns each class a method table. An object carries or implies a pointer to the table for its concrete class, and a method call loads the function from a known slot before calling it. Interface-based systems may use separate witness tables or other metadata, but the conceptual operation is the same: select behavior using runtime type information.

Dynamic dispatch differs from ordinary overload resolution. Overloading is often resolved statically from source-level types; dynamic dispatch deliberately postpones method selection until the receiver value is known.

This mechanism realizes subtype polymorphism operationally: callers use a common interface while different concrete values provide different behavior. Its costs—indirect calls, metadata and sometimes reduced optimization opportunities—follow directly from that late choice.