senseidb/bobo — pull request #10 by jhartman (2012-01-05 21:48:57+00:00)
Title: Fluent interfaces in bobo

Hi,

There are a lot of setter methods for many of the bobo api classes that currently return void. Take for example, BrowseRequest. It has methods like setFacetSpecs, setFilter, setGroupBy, setFacetDataHandler, setCount.... If you want to create a new BrowseRequest, you must do something like:

BrowseRequest bf = new BrowseRequest();
bf.setFacetSpecs(facetSpecs);
bf.setFilter(filter);
bf.setCount(10);
...

Instead, you could do

BrowseRequest bf = new BrowseRequest().setFacetSpecs(facetSpecs).setFilter(filter).setCount(10);

If you set more than 2 things, you can split it up over a line if you like. This is also nice if you create a new object, but you don't care about it's name. A great example of this is passing in an object into a method call.

runTest(new BrowseRequest().setFilter(filter));

Before, this would take 3 lines and now it can be done in one.