liveBook · Manning

Dispatch value

As explained in Data-Oriented Programming: Reduce software complexity

A dispatch value is the value produced from multimethod arguments that identifies which implementation should execute.

A dispatch value is the value produced from multimethod arguments to select the implementation that should run. A dispatch function computes it; methods handle particular values. section 13.2 section 13.6

Greeting animals without classes

A greet multimethod receives an animal map. Its dispatch function returns animal.type, producing values such as "dog", "cat", or "cow". Each value selects greetDog, greetCat, or greetCow. A default method handles an unmatched value such as "horse". section 13.2

A dispatch function also:

  • Defines the multimethod signature. section 13.6
  • Validates the arguments before emitting a value. section 13.6
  • Can emit multiple values when behavior depends on several arguments. section 13.6

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Explains computation, validation, method wiring, defaults, and single, multiple, and dynamic dispatch.
Examples
Uses animal type values for dog, cat, cow, and horse greeting implementations.
What it assumes
Assumes familiarity with function calls and data maps while explaining multimethod components from their basic roles.
What you can do after
Build it from scratch by defining a dispatch function and wiring methods to its emitted values.
How it connects
Connects dispatch functions with multimethods, methods, single dispatch, multiple dispatch, and dynamic dispatch.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.