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?

3 comments:

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.

http://stephan.reposita.org/archives/2007/10/17/creating-a-fluent-interface-for-google-collections/

http://stephan.reposita.org/archives/2007/10/10/fluent-interface-and-reflection-for-object-building-in-java/

Peace
-stephan


--
Stephan Schmidt :: stephan@reposita.org
Reposita Open Source - Monitor your software development
http://www.reposita.org
Blog at http://stephan.reposita.org - 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: http://martinfowler.com/dslwip/

Take a closer look at the internal DSL section: http://martinfowler.com/dslwip/InternalOverview.html

Regards,
Guilherme