tags:

views:

252

answers:

6

What's the term for this design?

object.method1().method2().method3()

..when all methods return *this?

I found the term for this a while ago, but lost it meanwhile. I have no clue how to search for this on google :) Also if anyone can think of a better title for the question, feel free to change it.

Thanks

Update-Gishu: After reading about it, I feel that your question is misleading w.r.t. code snippet provided.. (Feel free to rollback)

Method Chaining

object.method1().method2().method3()

Fluent Interfaces

private void makeFluent(Customer customer) {
        customer.newOrder()
                .with(6, "TAL")
                .with(5, "HPK").skippable()
                .with(3, "LGV")
                .priorityRush();
    }
+8  A: 

Looks to me like you are describing a fluent interface. Ive also heard it referred to as pipelineing or chaining.

Update-Gishu: http://martinfowler.com/bliki/FluentInterface.html

Joel Cunningham
that's it, thanks, the term was slipping my mind :)
Prody
Thanks for the link Gishu
Robert Gould
+7  A: 

method chaining

PW
+4  A: 

It's usually called method chaining. An example of its application is the Named Parameter Idiom.

As an aside, I find it amusing that searching in Google for "object method1 method2" comes up with exactly the page you were looking for. :)

Greg Hewgill
well, searching on Google doesn't get you any rep... ;)
Aardvark
+1  A: 

It's method chaining.

moogs
+1  A: 

chaining is a more common name in the industry and most developers have at least heard of it, while fluent interface is more academic and lots of people will have no idea what your talking about.

Robert Gould
A: 

You can find a good definitition and the basic concepts of the fluent interface this this post:

Guidelines to Fluent Interface design in C# part 1

I hope that helps.

Sir Gallahad