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

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
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
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
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
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
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
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

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