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

essence of dispatch
SMART_READER_LITE
LIVE PREVIEW

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?


slide-1
SLIDE 1

Essence of Dispatch

Damien Cassou, Stéphane Ducasse and Luc Fabresse

W3S02

http://www.pharo.org

slide-2
SLIDE 2

Remember: Implementing not in Two Methods

W3S02 2 / 14

slide-3
SLIDE 3

Stepping Back

Let the receiver decide Do not ask, tell W3S02 3 / 14

slide-4
SLIDE 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

slide-5
SLIDE 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

slide-6
SLIDE 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

slide-7
SLIDE 7

Question

Can we implement the same implementation for Not in only

  • ne class?

No NO NO! W3S02 7 / 14

slide-8
SLIDE 8

Classes Play Case Roles

To activate the choice operator we must have choices:

classes

A class represents a case W3S02 8 / 14

slide-9
SLIDE 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

slide-10
SLIDE 10

Advantages of Class Hierarchy

More modular: We can package different classes in different packages

W3S02 10 / 14

slide-11
SLIDE 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

slide-12
SLIDE 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

slide-13
SLIDE 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

slide-14
SLIDE 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/