SlideShare a Scribd company logo
1 of 19
Download to read offline
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

What's hot

F# Data: Making structured data first class citizens
F# Data: Making structured data first class citizensF# Data: Making structured data first class citizens
F# Data: Making structured data first class citizensTomas Petricek
 
Link Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
Link Discovery Tutorial Part III: Benchmarking for Instance Matching SystemsLink Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
Link Discovery Tutorial Part III: Benchmarking for Instance Matching SystemsHolistic Benchmarking of Big Linked Data
 
Python courses: lecture 1
Python courses: lecture 1Python courses: lecture 1
Python courses: lecture 1Ihor Khytrykh
 
Domain Specific Languages: The Functional Way
Domain Specific Languages: The Functional WayDomain Specific Languages: The Functional Way
Domain Specific Languages: The Functional WayTomas Petricek
 
Enhancing Entity Linking by Combining NER Models
Enhancing Entity Linking by Combining NER ModelsEnhancing Entity Linking by Combining NER Models
Enhancing Entity Linking by Combining NER ModelsJulien PLU
 
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...Julien PLU
 
[Question Paper] Web Technology (Revised Course) [April / 2015]
[Question Paper] Web Technology (Revised Course) [April / 2015][Question Paper] Web Technology (Revised Course) [April / 2015]
[Question Paper] Web Technology (Revised Course) [April / 2015]Mumbai B.Sc.IT Study
 
[Question Paper] Object Oriented Programming (Old Course) [April / 2014]
[Question Paper] Object Oriented Programming (Old Course) [April / 2014][Question Paper] Object Oriented Programming (Old Course) [April / 2014]
[Question Paper] Object Oriented Programming (Old Course) [April / 2014]Mumbai B.Sc.IT Study
 
Can Deep Learning Techniques Improve Entity Linking?
Can Deep Learning Techniques Improve Entity Linking?Can Deep Learning Techniques Improve Entity Linking?
Can Deep Learning Techniques Improve Entity Linking?Julien PLU
 
R Basics and Best Practices
R Basics and Best PracticesR Basics and Best Practices
R Basics and Best PracticesKristen Sauby
 

What's hot (20)

F# Data: Making structured data first class citizens
F# Data: Making structured data first class citizensF# Data: Making structured data first class citizens
F# Data: Making structured data first class citizens
 
Link Discovery Tutorial Part I: Efficiency
Link Discovery Tutorial Part I: EfficiencyLink Discovery Tutorial Part I: Efficiency
Link Discovery Tutorial Part I: Efficiency
 
Prototype Languages
Prototype LanguagesPrototype Languages
Prototype Languages
 
Link Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
Link Discovery Tutorial Part III: Benchmarking for Instance Matching SystemsLink Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
Link Discovery Tutorial Part III: Benchmarking for Instance Matching Systems
 
Link Discovery Tutorial Part V: Hands-On
Link Discovery Tutorial Part V: Hands-OnLink Discovery Tutorial Part V: Hands-On
Link Discovery Tutorial Part V: Hands-On
 
Link Discovery Tutorial Part II: Accuracy
Link Discovery Tutorial Part II: AccuracyLink Discovery Tutorial Part II: Accuracy
Link Discovery Tutorial Part II: Accuracy
 
Unit 5
Unit 5Unit 5
Unit 5
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Python courses: lecture 1
Python courses: lecture 1Python courses: lecture 1
Python courses: lecture 1
 
record_linking
record_linkingrecord_linking
record_linking
 
Domain Specific Languages: The Functional Way
Domain Specific Languages: The Functional WayDomain Specific Languages: The Functional Way
Domain Specific Languages: The Functional Way
 
1 구조체
1 구조체1 구조체
1 구조체
 
Bhushan Rathi
Bhushan RathiBhushan Rathi
Bhushan Rathi
 
Enhancing Entity Linking by Combining NER Models
Enhancing Entity Linking by Combining NER ModelsEnhancing Entity Linking by Combining NER Models
Enhancing Entity Linking by Combining NER Models
 
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
Knowledge extraction in Web media: at the frontier of NLP, Machine Learning a...
 
[Question Paper] Web Technology (Revised Course) [April / 2015]
[Question Paper] Web Technology (Revised Course) [April / 2015][Question Paper] Web Technology (Revised Course) [April / 2015]
[Question Paper] Web Technology (Revised Course) [April / 2015]
 
[Question Paper] Object Oriented Programming (Old Course) [April / 2014]
[Question Paper] Object Oriented Programming (Old Course) [April / 2014][Question Paper] Object Oriented Programming (Old Course) [April / 2014]
[Question Paper] Object Oriented Programming (Old Course) [April / 2014]
 
Can Deep Learning Techniques Improve Entity Linking?
Can Deep Learning Techniques Improve Entity Linking?Can Deep Learning Techniques Improve Entity Linking?
Can Deep Learning Techniques Improve Entity Linking?
 
R Basics and Best Practices
R Basics and Best PracticesR Basics and Best Practices
R Basics and Best Practices
 
23 data-structures
23 data-structures23 data-structures
23 data-structures
 

Viewers also liked

What Would You Say
What Would You SayWhat Would You Say
What Would You Sayguest123f4
 
Every Consumer is a Business user is a Consumer
Every Consumer is a Business user is a ConsumerEvery Consumer is a Business user is a Consumer
Every Consumer is a Business user is a ConsumerMichael Kogeler
 
M2MSys ITIL Executive Summary
M2MSys ITIL Executive SummaryM2MSys ITIL Executive Summary
M2MSys ITIL Executive SummaryFilipe Pinto
 
Poland by Saray
Poland by SarayPoland by Saray
Poland by Saraymsanz126
 
White certificates in Italy: a brief summary
White certificates in Italy: a brief summaryWhite certificates in Italy: a brief summary
White certificates in Italy: a brief summaryDario Di Santo
 
Emilia's Presentation
Emilia's PresentationEmilia's Presentation
Emilia's Presentationesoliman
 
What Would You Say
What Would You SayWhat Would You Say
What Would You Sayguest123f4
 
asal alma;lsm joiwoi
asal alma;lsm joiwoiasal alma;lsm joiwoi
asal alma;lsm joiwoierrorperson
 

Viewers also liked (18)

Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Reclassification
ReclassificationReclassification
Reclassification
 
What Would You Say
What Would You SayWhat Would You Say
What Would You Say
 
T+L Copy2
T+L Copy2T+L Copy2
T+L Copy2
 
Inheritance
InheritanceInheritance
Inheritance
 
Every Consumer is a Business user is a Consumer
Every Consumer is a Business user is a ConsumerEvery Consumer is a Business user is a Consumer
Every Consumer is a Business user is a Consumer
 
Type Systems
Type SystemsType Systems
Type Systems
 
M2MSys ITIL Executive Summary
M2MSys ITIL Executive SummaryM2MSys ITIL Executive Summary
M2MSys ITIL Executive Summary
 
Poland by Saray
Poland by SarayPoland by Saray
Poland by Saray
 
Nobel prize 1910
Nobel prize  1910Nobel prize  1910
Nobel prize 1910
 
SJSU at CSFUL Tompson Presentation
SJSU at CSFUL Tompson PresentationSJSU at CSFUL Tompson Presentation
SJSU at CSFUL Tompson Presentation
 
White certificates in Italy: a brief summary
White certificates in Italy: a brief summaryWhite certificates in Italy: a brief summary
White certificates in Italy: a brief summary
 
Emilia's Presentation
Emilia's PresentationEmilia's Presentation
Emilia's Presentation
 
Fathers Healing Hand
Fathers Healing HandFathers Healing Hand
Fathers Healing Hand
 
What Would You Say
What Would You SayWhat Would You Say
What Would You Say
 
Setup1
Setup1Setup1
Setup1
 
asal alma;lsm joiwoi
asal alma;lsm joiwoiasal alma;lsm joiwoi
asal alma;lsm joiwoi
 
België Nederland
België NederlandBelgië Nederland
België Nederland
 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 

Multiple Dispatch

  • 1.
  • 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