Stéphane Ducasse 1
Stéphane Ducasse
stephane.ducasse@inria.fr
http://stephane.ducasse.free.fr/
Precision about the
Cascade
S.Ducasse 2
Let’s be Precise!
• The semantics of the cascade is to send all the messages in the
cascade to the receiver of...
S.Ducasse 3
Let’s be Precise!
(OrderedCollection with: 1) add: 25; add: 35
In the example the FIRST message involved in th...
S.Ducasse 4
One Problem
(OrderedCollection with: 1)
add: 25;
add: 35
PrIt-> 35
One problem: the expression returns 35 and ...
S.Ducasse 5
Let’s analyze a bit…
OrderedCollection>>add: newObject
"Include newObject as one of the receiver's elements. A...
S.Ducasse 6
Yourself:Accessing the Receiver
• Use yourself
• yourself returns the receiver of the cascade.
(OrderedCollect...
S.Ducasse 7
Really got it?
yourself returns the receiver of the cascade:
Here the receiver of the cascade is a newly creat...
S.Ducasse 8
Of course!
Object>>yourself
^ self
Upcoming SlideShare
Loading in …5
×

8 - OOP - Cascade

747 views
701 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
747
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

8 - OOP - Cascade

  1. 1. Stéphane Ducasse 1 Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Precision about the Cascade
  2. 2. S.Ducasse 2 Let’s be Precise! • The semantics of the cascade is to send all the messages in the cascade to the receiver of the FIRST message involved in the cascade. • Workstation new name: #mac ; nextNode: aNode • Where the msg name: is sent to the newly created instance of workstation and the msg nextNode: too.
  3. 3. S.Ducasse 3 Let’s be Precise! (OrderedCollection with: 1) add: 25; add: 35 In the example the FIRST message involved in the cascade is the first add: msg and not #with:. So all the messages are sent to the result of the parenthesised expression, the newly created instance of anOrderedCollection
  4. 4. S.Ducasse 4 One Problem (OrderedCollection with: 1) add: 25; add: 35 PrIt-> 35 One problem: the expression returns 35 and not the collection object.
  5. 5. S.Ducasse 5 Let’s analyze a bit… OrderedCollection>>add: newObject "Include newObject as one of the receiver's elements. Answer newObject." ^self addLast: newObject OrderedCollection>>addLast: newObject "Add newObject to the end of the receiver. Answer newObject." lastIndex = self basicSize ifTrue: [self makeRoomAtLast]. lastIndex := lastIndex + 1. self basicAt: lastIndex put: newObject. ^newObject
  6. 6. S.Ducasse 6 Yourself:Accessing the Receiver • Use yourself • yourself returns the receiver of the cascade. (OrderedCollection with: 1) add: 25; add: 35 ; yourself -> OrderedCollection(1 25 35)
  7. 7. S.Ducasse 7 Really got it? yourself returns the receiver of the cascade: Here the receiver of the cascade is a newly created instance anOrderedCollection and not the class OrderedCollection.The self in the yourself method is linked to this instance (OrderedCollection with: 1) add: 25; add: 35 ; yourself anOrderedCollection(1) = self So what is the code of yourself?
  8. 8. S.Ducasse 8 Of course! Object>>yourself ^ self

×