Cascading messages
Last updated at 8:07 am UTC on 9 May 2018
Casading is a special syntax which allows multiple messages to be sent to the same object, The use of a ";" to concatenate messages together provides a compact form of notation and may eliminate the need for temporary variables.
anObject methodCall; anotherMethod call; another
A contrived example:
dict := Dictionary new.
dict at: #one put: 1; at: #two put: 2
The value returned by the cascading expresion is the value returned from the last message; intermediate returned objects are ignored. Many messages return self but others do not.
For example:
dict := Dictionary new at: #one put: 1; at: #two put: 2
sets dict to 2 not to a Dictionary(#one->1 #two->2 )
While
poly := PolygonMorph new borderWidth:2; arrowLength:4
Sets poly to a PolygonMorph(278)
Note also that
poly := PolygonMorph new; borderWidth:2; arrowLength:4
is, of course, entirely different - applying the cascaded messages to the Class PolygonMorph, not the instance of PolygonMorph.