Languages Features Calendar About Lists Add Language
GitHub icon

Single Dispatch

Single Dispatch

Single Dispatch is a language feature.

When the type of a single object is enough to determine what method to call.

Languages with Single Dispatch include Java, JavaScript, Python, C++, Swift, Objective-C, Common Lisp

Example from Common Lisp:

; (defclass Person () ()) (defmethod frobnicate ((p Person) record spreadsheet) (format t "~a ~a ~a~&" (type-of p) (type-of record) (type-of spreadsheet))) (defclass Asteroid () ()) (defmethod frobnicate ((a Asteroid) velocity size) ; do stuff ) ; At runtime these 2 would be routed to respective methods: (frobnicate a-person his-record big-spreadsheet) (frobnicate an-asteroid very-fast pretty-small)

Article source

PLDB - Build the next great programming language. v5.0.0 - Acknowledgements · Email · GitHub