Double Dispatch

noun

say it: “DUB-ul dih-SPACH” /ˈdʌbəl dɪˈspætʃ/

Choosing which code runs by two things at once, the kind of object and the kind of job, by making two calls in a row.

What is double dispatch?

Double dispatch picks the code to run by two things, using two calls. In the Visitor pattern, rule.accept(describer) first runs the code for the rule's own kind, and that code calls describer.visit_and(rule), which runs the code for the job.

In a sentence

  • “The rule's accept method and the visitor's visit method together make double dispatch: one call picks the kind of piece, the next picks the job.”

Level: Master · More OOP terms at this level

Updated