Multiple Dispatch is an actively used design pattern created in 2007. Multiple dispatch or multimethods is a feature of some programming languages in which a function or method can be dynamically dispatched based on the run time (dynamic) type or, in the more general case some other attribute, of more than one of its arguments. This is a generalization of single dispatch polymorphism where a function or method call is dynamically dispatched based on the derived type of the object on which the method has been called. Multiple dispatch routes the dynamic dispatch to the implementing function or method using the combined characteristics of one or more arguments.. Read more on Wikipedia...

12Years Old
  • Multiple Dispatch ranks in the top 25% of entities I track
  • the Multiple Dispatch wikipedia page
  • Multiple Dispatch first appeared in 2007
  • Have a question about Multiple Dispatch not answered here? Email me and let me know how I can help.

Languages without Multiple Dispatch include javascript

Languages with Multiple Dispatch include common-lisp, dylan, julia, smalltalk

Example from common-lisp:

 (defmethod collide-with ((x asteroid) (y asteroid))
  ;; deal with asteroid hitting asteroid
  )
(defmethod collide-with ((x asteroid) (y spaceship))
  ;; deal with asteroid hitting spaceship
  )
(defmethod collide-with ((x spaceship) (y asteroid))
  ;; deal with spaceship hitting asteroid
  )
(defmethod collide-with ((x spaceship) (y spaceship))
  ;; deal with spaceship hitting spaceship
  )

Example from julia:

collide_with(x::Asteroid, y::Asteroid) = ... # deal with asteroid hitting asteroid
collide_with(x::Asteroid, y::Spaceship) = ... # deal with asteroid hitting spaceship
collide_with(x::Spaceship, y::Asteroid) = ... # deal with spaceship hitting asteroid
collide_with(x::Spaceship, y::Spaceship) = ... # deal with spaceship hitting spaceship

Last updated February 18th, 2020

Edit Multiple Dispatch on GitHub