Multiple Dispatch

699 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
699
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
43
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Multiple Dispatch

  1. 1. 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
  2. 2. 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
  3. 3. Types of Dispatch Static dispatch. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
  4. 4. Types of Dispatch Static dispatch. Single dispatch. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 3 / 8
  5. 5. 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
  6. 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. 7. 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
  8. 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
  9. 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. Resembles (in a way) pattern matching. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 4 / 8
  10. 10. Advantages More natural interaction with overloading. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 5 / 8
  11. 11. 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
  12. 12. 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
  13. 13. Disadvantages May be slightly confusing. Michal P´ıˇse (CTU in Prague) Object Programming L. 6: Multiple Dispatch November 2, 2010 6 / 8
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. 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

×