Amazon, jQuery and Fluent Interfaces

Since adding my library, one of things that I wanted to do was leverage the Amazon API a little better and perhaps implement the ability to add books in a fashion a little more akin to that used by LinkedIn for their book library widget. When researching ways to do this, I came across the Zend framework’s Zend_Service_Amazon. One of the things it implements is a query API that resembles the Fluent Interface design pattern, a pattern I was already using with jQuery with the ability to “chain” methods together, but something I didn’t have a name for and hadn’t thought about in a larger fashion for other languages and how useful it would be to use with Swing in Java (“If Java Swing libraries supported this kind of coding…”).

Of course, one of the big reasons to use fluent interfaces is some constructors can wind up being rather long with a number of parameters. This is less of an issue with modern IDEs and autocompletion, but the solution of fluent interfaces still feels more elegant. As a case in point about complexity, there’s an excellent example of fluent interface implementation in Java for an insurance application. Of course, this means I’m now going to explore the Builder Design Pattern and Domain Specific Languages further.

Both comments and pings are currently closed.

Comments are closed.