Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 3
    A fluent interface is a matter of style. If you are writing an API provide alternative forms to it. Commented Mar 2, 2012 at 14:55
  • 1
    For more discussion, take a look at this question: programmers.stackexchange.com/questions/69519/… Commented Mar 2, 2012 at 15:01
  • @Oded It is possible to use such an API without chaining by just making each call a separate statement, or did you have another idea for an alternative? Commented Mar 2, 2012 at 15:04
  • @GarrettHall - Of course it is possible, but then you end up calling things like menu.withStyle("") without context. You need two APIs in such a case. Commented Mar 2, 2012 at 15:08
  • 2
    @GarrettHall The point of the 'fluent interface' is the method chain, which is meant to be read like a sentence. In this sense, the long method chain is not considered bad. But, and here I agree with Oded, it would be best to also provide the same functionality in a more conventional syntax. That way, the developer can choose which method to use. Commented Mar 2, 2012 at 15:11