[ImageJ-devel] API Design Question - Fluent Interface / Method Chaining

Curtis Rueden ctrueden at wisc.edu
Tue Apr 13 14:29:43 CDT 2010


Hi Grant,

The Fluent pattern is pretty neat, but I agree with Fowler's assessment of
the downside:

"One of the problems of methods in a fluent interface is that they don't
make much sense on their own. Looking at a method browser of method by
method documentation doesn't show much sense to with. Indeed sitting there
on its own I'd argue that it's a badly named method that doesn't communicate
its intent at all well. It's only in the context of the fluent action that
it shows its strengths. One way around this may be to use builder objects
that are only used in this context."

I think his idea of using fluent builder objects to ease creation of object
state would make the core classes a lot more readable (since the core
classes themselves would not be cluttered with weird methods like "with").

-Curtis

On Tue, Apr 13, 2010 at 11:22 AM, Grant B. Harris <gharris at mbl.edu> wrote:

>
> Anybody have any thoughts on the use of a Fluent Interface<http://martinfowler.com/bliki/FluentInterface.html>(Fowler) style (also known as Method
> Chaining <http://www.factorypattern.com/method-chaining>) in the design of
> an API.  Essentially, by returning the object instance from the setter
> methods, you can chain calls, like:
>
> Rectangle().setX(10).setY(10).setWidth(13).setHeight(15).setColor("red");
>
> --
>
> Grant Harris
>
>
>
> _______________________________________________
> ImageJ-devel mailing list
> ImageJ-devel at imagejdev.org
> http://imagejdev.org/mailman/listinfo/imagej-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20100413/fa996738/attachment.html>


More information about the ImageJ-devel mailing list