SlideShare a Scribd company logo
Multiple Dispatch
Motivation
void f(String o) { ... }
void f(Object o) { ... }
Object o = new String("foo");
f(o);
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 2 / 8
Motivation
void f(String o) { ... }
void f(Object o) { ... }
Object o = new String("foo");
f(o);
Invoked function may change with the static type of o.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 2 / 8
Types of Dispatch
Static dispatch.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
Types of Dispatch
Static dispatch.
Single dispatch.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
Types of Dispatch
Static dispatch.
Single dispatch.
Multiple dispatch.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
Types of Dispatch
Static dispatch.
Single dispatch.
Multiple dispatch.
. . .
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
Multiple Dispatch
Method lookup is based on runtime classes of parameters.
Does not depend on static types of parameters.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 4 / 8
Multiple Dispatch
Method lookup is based on runtime classes of parameters.
Does not depend on static types of parameters.
Can be emulated (albeit in a restricted fashion) by the visitor pattern.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 4 / 8
Multiple Dispatch
Method lookup is based on runtime classes of parameters.
Does not depend on static types of parameters.
Can be emulated (albeit in a restricted fashion) by the visitor pattern.
Resembles (in a way) pattern matching.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 4 / 8
Advantages
More natural interaction with overloading.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 5 / 8
Advantages
More natural interaction with overloading.
More equal parameters.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 5 / 8
Advantages
More natural interaction with overloading.
More equal parameters.
Better composability.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 5 / 8
Disadvantages
May be slightly confusing.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 6 / 8
Disadvantages
May be slightly confusing.
Blurred notion of method containment.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 6 / 8
Disadvantages
May be slightly confusing.
Blurred notion of method containment.
The diamond problem may cause ambiguity.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 6 / 8
CZ
Multiple dispatch only works across inheritance hierarchy (not across
requires hierarchy).
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 7 / 8
CZ
Multiple dispatch only works across inheritance hierarchy (not across
requires hierarchy).
No diamonds in inheritance hierarchy.
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 7 / 8
See
Malayeri, D. and Aldrich, J. CZ: Multiple Inheritance Without
Diamonds. Proceeding of the 24th ACM SIGPLAN Conference on Object
Oriented Programming Systems Languages and Applications. 21–40.
http://doi.acm.org/10.1145/1640089.1640092
Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 8 / 8

More Related Content

PDF
Subtyping
Michal Píše
 
PDF
Functional Concepts
Michal Píše
 
PDF
Reflection and Metadata
Michal Píše
 
PDF
[Question Paper] Web Technology (Revised Course) [June / 2016]
Mumbai B.Sc.IT Study
 
PDF
Multiple Inheritance
Michal Píše
 
PPTX
F# and Financial Data Making Data Analysis Simple
Tomas Petricek
 
PDF
Flow Control
Michal Píše
 
PPTX
Effective Data Analysis with Deedle
Howard Mansell
 
Subtyping
Michal Píše
 
Functional Concepts
Michal Píše
 
Reflection and Metadata
Michal Píše
 
[Question Paper] Web Technology (Revised Course) [June / 2016]
Mumbai B.Sc.IT Study
 
Multiple Inheritance
Michal Píše
 
F# and Financial Data Making Data Analysis Simple
Tomas Petricek
 
Flow Control
Michal Píše
 
Effective Data Analysis with Deedle
Howard Mansell
 

What's hot (20)

PPTX
F# Data: Making structured data first class citizens
Tomas Petricek
 
PDF
Link Discovery Tutorial Part I: Efficiency
Holistic Benchmarking of Big Linked Data
 
PDF
Prototype Languages
Michal Píše
 
PDF
Link Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
Holistic Benchmarking of Big Linked Data
 
PDF
Link Discovery Tutorial Part V: Hands-On
Holistic Benchmarking of Big Linked Data
 
PDF
Link Discovery Tutorial Part II: Accuracy
Holistic Benchmarking of Big Linked Data
 
PDF
Garbage Collection
Michal Píše
 
PPTX
Python courses: lecture 1
Ihor Khytrykh
 
PDF
record_linking
Robert Berry
 
PPTX
Domain Specific Languages: The Functional Way
Tomas Petricek
 
PDF
Bhushan Rathi
Bhushan Rathi
 
PDF
Enhancing Entity Linking by Combining NER Models
Julien PLU
 
PDF
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Julien PLU
 
PDF
[Question Paper] Web Technology (Revised Course) [April / 2015]
Mumbai B.Sc.IT Study
 
PDF
[Question Paper] Object Oriented Programming (Old Course) [April / 2014]
Mumbai B.Sc.IT Study
 
PDF
Can Deep Learning Techniques Improve Entity Linking?
Julien PLU
 
PDF
R Basics and Best Practices
Kristen Sauby
 
PDF
23 data-structures
Hadley Wickham
 
F# Data: Making structured data first class citizens
Tomas Petricek
 
Link Discovery Tutorial Part I: Efficiency
Holistic Benchmarking of Big Linked Data
 
Prototype Languages
Michal Píše
 
Link Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
Holistic Benchmarking of Big Linked Data
 
Link Discovery Tutorial Part V: Hands-On
Holistic Benchmarking of Big Linked Data
 
Link Discovery Tutorial Part II: Accuracy
Holistic Benchmarking of Big Linked Data
 
Garbage Collection
Michal Píše
 
Python courses: lecture 1
Ihor Khytrykh
 
record_linking
Robert Berry
 
Domain Specific Languages: The Functional Way
Tomas Petricek
 
Bhushan Rathi
Bhushan Rathi
 
Enhancing Entity Linking by Combining NER Models
Julien PLU
 
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Julien PLU
 
[Question Paper] Web Technology (Revised Course) [April / 2015]
Mumbai B.Sc.IT Study
 
[Question Paper] Object Oriented Programming (Old Course) [April / 2014]
Mumbai B.Sc.IT Study
 
Can Deep Learning Techniques Improve Entity Linking?
Julien PLU
 
R Basics and Best Practices
Kristen Sauby
 
23 data-structures
Hadley Wickham
 
Ad

Viewers also liked (18)

PDF
Encapsulation
Michal Píše
 
PDF
Reclassification
Michal Píše
 
PPT
What Would You Say
guest123f4
 
PDF
T+L Copy2
brownc847
 
PDF
Inheritance
Michal Píše
 
PDF
Every Consumer is a Business user is a Consumer
Michael Kogeler
 
PDF
Type Systems
Michal Píše
 
PDF
M2MSys ITIL Executive Summary
Filipe Pinto
 
PPT
Poland by Saray
msanz126
 
PPT
Nobel prize 1910
Pratyush Chaudhuri
 
PDF
SJSU at CSFUL Tompson Presentation
Sara R. Tompson, M.S.
 
PDF
White certificates in Italy: a brief summary
Dario Di Santo
 
PPT
Emilia's Presentation
esoliman
 
PPT
Fathers Healing Hand
Studio 18 Productions
 
PPT
What Would You Say
guest123f4
 
PPT
Setup1
Adefraeije
 
TXT
asal alma;lsm joiwoi
errorperson
 
PPT
België Nederland
Johan Bracke
 
Encapsulation
Michal Píše
 
Reclassification
Michal Píše
 
What Would You Say
guest123f4
 
T+L Copy2
brownc847
 
Inheritance
Michal Píše
 
Every Consumer is a Business user is a Consumer
Michael Kogeler
 
Type Systems
Michal Píše
 
M2MSys ITIL Executive Summary
Filipe Pinto
 
Poland by Saray
msanz126
 
Nobel prize 1910
Pratyush Chaudhuri
 
SJSU at CSFUL Tompson Presentation
Sara R. Tompson, M.S.
 
White certificates in Italy: a brief summary
Dario Di Santo
 
Emilia's Presentation
esoliman
 
Fathers Healing Hand
Studio 18 Productions
 
What Would You Say
guest123f4
 
Setup1
Adefraeije
 
asal alma;lsm joiwoi
errorperson
 
België Nederland
Johan Bracke
 
Ad

Recently uploaded (20)

PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
How to Apply for a Job From Odoo 18 Website
Celine George
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
CDH. pptx
AneetaSharma15
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
How to Apply for a Job From Odoo 18 Website
Celine George
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
CDH. pptx
AneetaSharma15
 

Multiple Dispatch

  • 2. Motivation void f(String o) { ... } void f(Object o) { ... } Object o = new String("foo"); f(o); Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 2 / 8
  • 3. Motivation void f(String o) { ... } void f(Object o) { ... } Object o = new String("foo"); f(o); Invoked function may change with the static type of o. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 2 / 8
  • 4. Types of Dispatch Static dispatch. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
  • 5. Types of Dispatch Static dispatch. Single dispatch. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
  • 6. Types of Dispatch Static dispatch. Single dispatch. Multiple dispatch. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
  • 7. Types of Dispatch Static dispatch. Single dispatch. Multiple dispatch. . . . Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
  • 8. Multiple Dispatch Method lookup is based on runtime classes of parameters. Does not depend on static types of parameters. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 4 / 8
  • 9. Multiple Dispatch Method lookup is based on runtime classes of parameters. Does not depend on static types of parameters. Can be emulated (albeit in a restricted fashion) by the visitor pattern. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 4 / 8
  • 10. Multiple Dispatch Method lookup is based on runtime classes of parameters. Does not depend on static types of parameters. Can be emulated (albeit in a restricted fashion) by the visitor pattern. Resembles (in a way) pattern matching. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 4 / 8
  • 11. Advantages More natural interaction with overloading. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 5 / 8
  • 12. Advantages More natural interaction with overloading. More equal parameters. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 5 / 8
  • 13. Advantages More natural interaction with overloading. More equal parameters. Better composability. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 5 / 8
  • 14. Disadvantages May be slightly confusing. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 6 / 8
  • 15. Disadvantages May be slightly confusing. Blurred notion of method containment. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 6 / 8
  • 16. Disadvantages May be slightly confusing. Blurred notion of method containment. The diamond problem may cause ambiguity. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 6 / 8
  • 17. CZ Multiple dispatch only works across inheritance hierarchy (not across requires hierarchy). Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 7 / 8
  • 18. CZ Multiple dispatch only works across inheritance hierarchy (not across requires hierarchy). No diamonds in inheritance hierarchy. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 7 / 8
  • 19. See Malayeri, D. and Aldrich, J. CZ: Multiple Inheritance Without Diamonds. Proceeding of the 24th ACM SIGPLAN Conference on Object Oriented Programming Systems Languages and Applications. 21–40. http://doi.acm.org/10.1145/1640089.1640092 Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 8 / 8