Thursday, January 18, 2007
Wednesday, January 17, 2007
FluentInterface
I've posted before about the StringBuilder tip in .NET.
Martin Fowler describes this as an ExpressionBuilder pattern.
More formal terms are described in his post, for instance, a FluentInterface which allows code like this:
customer.newOrder() .with(6, "TAL") .with(5, "HPK").skippable() .with(3, "LGV").priorityRush();
I personally like this style but agree that if every object had these strange looking methods it would certainly pollute an API.
Another formal term describing how not to pollute an API is CommandQuerySeparation. Basically, this means that a method that changes the observable state of an object shouldn't have a return value.
The ExpressionBuilder pattern is the solution to this: it is a seperate object that defines the FluentInterface and yet doesn't pollute the API.
I'm glad that I now know more than 3 patterns, the Factory pattern, the Visitor pattern, and the Submarine pattern.