Malcolm Edgar writes:
> writing code using method chaining. Its something I have argued
> against for a long time, as its something I would never recommend
> developers do in their application code because you can get the train
> wreak anti-pattern.
For the record, I don't think method chaining as I had suggested results
in the train wreck anti-pattern. In the chain of method calls, you are
setting several properties on the *same* object:
anObject.text("text").width(50).height(50);
The train wreck anti-pattern, on the other hand, is when you chain
methods to get the information you need, digging too deep inside your
model and becoming vulnerable to any changes to the model along the
chain:
employee.getDepartment().getManager().getOffice().getAddress().getZip()
Here you are dependent on too many *different* objects.
Just thought I'd set that straight, because I wouldn't want people
to think that implementing method chaining in some Click objects
would be done "despite" the train wreck anti-pattern. That is a
different case and indeed a bad practice to be avoided, absolutely.
Cheers,
Freddy