liveBook · Manning

Polymorphic dispatch

Also called dispatch function

Polymorphic dispatch is runtime selection of an operation implementation based on a call's arguments, function value, or context.

How 2 Manning books explain it

Data-Oriented Programming: Reduce software complexity

A dispatch function is a function that defines a multimethod's signature, validates its arguments, and emits a value used to select an implementation.

How it is used
Uses dispatch functions to separate multimethod call signatures and selection logic from method implementations.
How deep it goes
Explains signatures, validation, single, multiple, and dynamic dispatch with JavaScript examples, but does not develop their implementation machinery.
Examples
Demonstrates animal greetings selected by type, animal-language pairs, and animal type combined with name length.
What you can do after
Build multimethods whose behavior varies by one argument, several arguments, or runtime-derived values.

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

Clojure: The Essential Reference

A dispatch function is a callable operation that selects and invokes an implementation based on an argument's dispatch value.

How it is used
Selects behavior for data-driven operations and supports flexible polymorphism beyond type-based method selection.
How deep it goes
Defines dispatch functions, implementations, hierarchies, ambiguity resolution, extension, removal, inspection, and failure behavior.
Examples
Demonstrates expression evaluation, custom operation hierarchies, runtime extension, method removal, ambiguity resolution, recursion, and exceptions.
What you can do after
Build it from scratch using defmulti, defmethod, custom hierarchies, default methods, and protocol extensions.

Read how Clojure: The Essential Reference explains polymorphic dispatch →

Also covered in

What to know first

Related concepts

Questions about polymorphic dispatch

What is polymorphic dispatch?

Polymorphic dispatch is runtime selection of an operation implementation based on a call's arguments, function value, or context.

Which Manning books explain polymorphic dispatch?

Data-Oriented Programming: Reduce software complexity and Clojure: The Essential Reference.

What should I know before learning polymorphic dispatch?

Manning books that teach polymorphic dispatch usually introduce polymorphism first.

What is the difference between polymorphic dispatch and contract?

Polymorphic dispatch is runtime selection of an operation implementation based on a call's arguments, function value, or context. A contract is an agreed specification of the conditions, expectations, rights, or obligations that govern behavior or interactions between parties or software components.

What kinds of polymorphic dispatch are there?

Kinds of polymorphic dispatch include type-based dispatch.

What is polymorphic dispatch part of?

Polymorphic dispatch is part of multimethod. A multimethod is a dispatch mechanism that selects an implementation by applying a dispatch function to multiple arguments, often using their runtime types or values.

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.