essence of dispatch
play

Essence of Dispatch Damien Cassou, Stphane Ducasse and Luc Fabresse - PowerPoint PPT Presentation

Essence of Dispatch Damien Cassou, Stphane Ducasse and Luc Fabresse W3S02 http://www.pharo.org Remember: Implementing not in Two Methods W3S02 2 / 14 Stepping Back Let the receiver decide Do not ask, tell W3S02 3 / 14 Ok So What?


  1. Essence of Dispatch Damien Cassou, Stéphane Ducasse and Luc Fabresse W3S02 http://www.pharo.org

  2. Remember: Implementing not in Two Methods W3S02 2 / 14

  3. Stepping Back � Let the receiver decide � Do not ask, tell W3S02 3 / 14

  4. Ok So What? � You will probably never implement Booleans in the future � So is it really that totally useless? � What is the lesson to learn? W3S02 4 / 14

  5. Message Sends Act as Case Statements � Message sends act as case statements � But with messages, the case statement is dynamic in the sense that it depends on the objects to which the message is sent W3S02 5 / 14

  6. Sending a Message is Making a Choice � Each time you send a message, the execution selects the right method depending on the class of the receiver � Sending a message is a choice operator W3S02 6 / 14

  7. Question Can we implement the same implementation for Not in only one class? � No � NO � NO! W3S02 7 / 14

  8. Classes Play Case Roles � To activate the choice operator we must have choices: classes � A class represents a case W3S02 8 / 14

  9. A Class Hierarchy is a Skeleton for Dynamic Dispatch Compare the solution with one class vs. a hierarchy � More modular � Hierarchy provides a way to specialize behavior � You only focus on one class at a time W3S02 9 / 14

  10. Advantages of Class Hierarchy More modular: We can package different classes in different packages W3S02 10 / 14

  11. Let the Receiver Decide � Sending a message lets the receiver decide � Client does not have to decide � Client code is more declarative: give orders � Different receivers may be substitued dynamically W3S02 11 / 14

  12. Avoid Conditionals � Use objects and messages, when you can � The execution engine acts as a conditional switch: Use it! � Check the AntiIfCampaign W3S02 12 / 14

  13. Summary: Cornerstone of OOP � Let the receiver decide � Message sends act as potential dynamic conditionals � Class hierarchy: a skeleton for dynamic dispatch � Avoid conditionals W3S02 13 / 14

  14. A course by and in collaboration with Inria 2016 Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France https://creativecommons.org/licenses/by-nc-nd/3.0/fr/

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend