Saturday, January 12, 2008

Searching for more Fluent API patterns for Java

Previous posts cover three patterns commonly seen in Fluent APIs in Java.
  1. Method Chaining
  2. Nested Interfaces
  3. Fluent Builder
So far these are the only Fluent patterns that I have seen used successfully in Java. Does anyone have any examples of Fluent APIs in Java that don't use one of these techniques?


Stephan said...

People use static imports in Java for fluent interfaces.

Like times(5).withPerson(person).delete()

the times() method call being a static import.

I'm very interested in that topic, other posts about fluent interfaces I've written are about a fluent interface to Google collections or automatically create a fluent implementation for an interface.


Stephan Schmidt ::
Reposita Open Source - Monitor your software development
Blog at - No signal. No noise.

Steve Asher said...

Good point, Stephan. I also use static imports heavily when using Fluent APIs. Without this Java 5 feature, it would be significantly more difficult to create code that resembles natural language sentences.

Guilherme Chapiewski said...

Hi Steve,

I suggest that you take a look in Martin Fowler's research about DSLs. The address is:

Take a closer look at the internal DSL section: