Method cascades are a syntactic nicety to avoid having to repeat the receiver of a series of methods.
Method cascades are a syntactic nicety to avoid having to repeat the receiver of a series of methods. They notably exist in smalltalk and dart.
In Smalltalk, this:
| window |
window := Window new.
window label: 'Hello'.
window open
can be cascaded like this:
Window new
label: 'Hello';
open
In Dart, this:
var address = getAddress();
address.setStreet(“Elm”, “13a”);
address.city = “Carthage”;
address.state = “Eurasia”
address.zip(66666, extended: 6666);
Can be cascaded like this:
getAddress()
..setStreet(“Elm”, “13a”)
..city = “Carthage”
..state = “Eurasia”
..zip(66666, extended: 6666);