liveBook · Manning

Dynamic dispatch

Also called virtual dispatch

Dynamic dispatch is runtime selection of an operation implementation according to an object's dynamically determined type or runtime arguments.

How 2 Manning books explain it

Data-Oriented Programming: Reduce software complexity

Dynamic dispatch is runtime selection of an operation implementation based on runtime argument information rather than only static types.

How it is used
Uses runtime data to extend polymorphic behavior beyond single- and multiple-argument type selection.
How deep it goes
Explains dispatch functions, validation, emitted values, method wiring, defaults, and testing through a complete example.
Examples
Demonstrates dysGreet with dog, cat, and cow maps, combining animal type with whether a name exceeds five letters.
What you can do after
Build it from scratch with a dispatch function and methods keyed by runtime values.

Read how Data-Oriented Programming: Reduce software complexity explains dynamic dispatch →

Idiomatic Rust

Dynamic dispatch is runtime selection of an implementation based on the concrete type behind an interface value.

How it is used
Stores different concrete types behind one trait interface and calls shared trait methods at runtime.
How deep it goes
Explains `dyn` trait objects, vtable-based lookup, and pointer requirements for unsized values.
Examples
Demonstrates two structs in a boxed trait-object vector and dispatches their shared method.
What you can do after
Build a heterogeneous `Vec<Box<dyn MyTrait>>` and invoke the shared trait method.

Read how Idiomatic Rust explains dynamic dispatch →

Also covered in

What to know first

Related concepts

Questions about dynamic dispatch

What is dynamic dispatch?

Dynamic dispatch is runtime selection of an operation implementation according to an object's dynamically determined type or runtime arguments.

Which Manning books explain dynamic dispatch?

Data-Oriented Programming: Reduce software complexity and Idiomatic Rust.

What should I know before learning dynamic dispatch?

Manning books that teach dynamic dispatch usually introduce heap, stack, array and trait first.

What is the difference between dynamic dispatch and static dispatch?

Dynamic dispatch is runtime selection of an operation implementation according to an object's dynamically determined type or runtime arguments. Static dispatch is the compile-time selection of a function or method implementation based on concrete types.

What is dynamic dispatch a kind of?

Dynamic dispatch is a kind of polymorphism. Polymorphism is a programming-language capability that lets a common operation or interface work with values of different types, with behavior or implementation determined by the type or value.

What is dynamic dispatch also called?

Dynamic dispatch is also called virtual dispatch.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.