views:

78

answers:

4

I know this is the Builder pattern, but it's a modified form of it. Whereas the Wikipedia article on Builder pattern gives the example:

pizzaBuilder.createNewPizzaProduct();
pizzaBuilder.buildDough();
pizzaBuilder.buildSauce();
pizzaBuilder.buildTopping();
Pizza p = pizzaBuilder.getPizza();

Is there a specific name for the modified Builder pattern which looks like:

Pizza p = pizzaBuilder.createNewPizzaProduct().buildDough().buildSauce().buildTopping();

This is best seen in the jQuery library, where you can do something like:

$('li.item-a').parent().css('background-color', 'red');

Where each method, including the initial $(), returns a jQuery object which typically represents a set of page elements, and each method operates on that set in some way.

+1  A: 

In C++, it is called (at least by one site) "Named Parameter Idiom".

KennyTM
+4  A: 

I've seen this called a Fluent Builder several places.

This makes a lot of sense, since it's basically a combination of a Fluent Interface and the Builder design pattern.

Mark Seemann
That's a perfect name (it communicates exactly what it is) +1
Pascal Thivent
I agree, that does sound like the perfect name. Not only that, but I'd never heard of the term "Fluent interface" before, so I will go read more about other fluent techniques!
Ricket
+3  A: 

It can be called a Fluent interface:

In software engineering, a fluent interface (as first coined by Eric Evans and Martin Fowler) is a way of implementing an object oriented API in a way that aims to provide for more readable code.

A fluent interface is normally implemented by using method chaining to relay the instruction context of a subsequent call (but a fluent interface entails more than just method chaining)

ChrisF
+2  A: 

I would call the technique "method chaining".

(pretty much in accordance with wikipedia...)

And yes, method chaining can be used to build fluent interfaces.

mookid8000