return the next context of computation, enable simple and flexible sequencing of computation
Motivation
We want to provide a small domain specific language to improve the readability of the code
Implementation
return the next expected object (state)
Examples
class fluent_class {
var $state_var;
function self_next( $arg ) {
....
return $this;
}
function other_next( $arg ) {
....
return $this->another;
}
}
$obj = new fluent_class();
$obj->self_next(1)
->self_next(2)
->other_next(3)
->something_else(4);
Note
This is an awkward idea to explain in words. Essentially you are delegating the desision what is the next object in the chain to the executable methods. It probably should be combined with weaving the values, which we would otherwise return, using accumulator style passing, or some other store method.
Have a look at Jonnay's post for better and more sensible code examples and the Fluenter class.
I sometimes look at this as the imperative "version" of continuation passing, but let's not even get there.