February 11, 2006
Jay Fields writes about using chaining for object initialisation.
One of the inspirations for the fluent interface style in jMock was a Smalltalk construct called cascade, which sends multiple message to the same object.
aThing one: 'one';
I just got fed up having to redeclare the same object
Posted by stevef at February 11, 2006 11:29 AM
I like this. I've been trying to use a similar style in writing functional tests recently, to make them more readable (more like English sentences).
In the Martin Fowler article you link to, he says "I saw Steve Freeman and Nat Price give an excellent talk at JAOO2005 on the evolution of the JMock API, they promised to write up their experiences but haven't. Someone please kidnap their compilers until they do." *Ahem*.
I've got a little time coming up so, unless I get swamped with admin, maybe I can finally get something done.
OK. We've written up a paper and submitted it to OOPLSA for this year. We'll post as much as we can as soon as they let us know.
The StringBuilder-class in .NET has some methods that return the instance itself, mimicking cascading:
StringBuilder sb = new StringBuilder();
Off course, this is pretty artificial, and only works on classes that are designed that way and when your methods don't return anything else.