Questions tagged [fluent-interface]

Refers to a practice of coding object-oriented APIs with the aim of improving readability of the interface, normally implemented using method chaining. The phrase was first coined by Eric Evans and Martin Fowler.

Martin Fowler's explanation on what he considers to be the proper way to design fluent interfaces can be found at http://www.martinfowler.com/bliki/FluentInterface.html.

Related concepts:

437 questions
15
votes
3 answers

Trying to understand how to create fluent interfaces, and when to use them

How would one create a fluent interface instead of a more tradition approach? Here is a traditional approach: Interface: interface IXmlDocumentFactory { XmlDocument CreateXml() //serializes just the data XmlDocument…
Matt
  • 14,353
  • 5
  • 53
  • 65
15
votes
3 answers

Is there a fluent assertion API for MSTest?

I've recently been exposed to the fluent interface in nUnit and I love it; however, I am using msTest. Does anyone know if there is a fluent interface that is either testing framework agnostic or for msTest?
JoshBerke
  • 66,142
  • 25
  • 126
  • 164
14
votes
6 answers

How to make Spring accept fluent (non-void) setters?

I have an API which I am turning into an internal DSL. As such, most methods in my PoJos return a reference to this so that I can chain methods together declaratively as such (syntactic sugar). myComponent .setID("MyId") .setProperty("One") …
Chris
  • 4,450
  • 3
  • 38
  • 49
14
votes
2 answers

Unable to determine the principal end of an association - Entity Framework Model First

I have created Entity Data Model in Visual Studio. Now I have file with SQL queries and C# classes generated from Model. Question: Classes are generated without annotations or code behind (Fluent API). Is it OK? I tried to run my application but…
Michal
  • 343
  • 1
  • 5
  • 16
14
votes
4 answers

Fluent APIs - return this or new?

I recently came up to an interesting question, what should fluent methods return? Should they change state of current object or create a brand new one with new state? In case this short description is not very intuitive here's an (unfortunaltely)…
Rustam
  • 1,766
  • 18
  • 34
13
votes
1 answer

Does Entity Framework Code First allow for fluent mappings in separate files?

I am developing a rather large database schema using Entity Framework Code First. I prefer the Fluent API over the Data Annotations approach, as it leaves my domain objects as simple POCOs. In order to use Fluent API, I have to override…
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
13
votes
7 answers

Fluent interfaces and leaky abstractions

What is a fluent interface? I can't find a good definition of this, but all I get are long code examples in a language I am not very familiar with (e.g. C++). Also, what is a leaky abstraction? Thanks
GurdeepS
  • 65,107
  • 109
  • 251
  • 387
13
votes
1 answer

Generic 'TThis' for fluent classes

I'm constructing a fluent interface where I have a base class that contains the bulk of the fluent logic, and a derived class that add some specialized behavior. The problem I'm facing is the return type of the fluent methods in the base class when…
Paul Alexander
  • 31,970
  • 14
  • 96
  • 151
12
votes
4 answers

No type inference with generic extension method

I have the following method: public static TEventInvocatorParameters Until (this TEventInvocatorParameters p, Func breakCond) where…
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
12
votes
7 answers

Is there any disadvantage to returning this instead of void?

Say instead of returning void a method you returned a reference to the class even if it didn't make any particular semantic sense. It seems to me like it would give you more options on how the methods are called, allowing you to use it in a…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
12
votes
5 answers

Does including prepositions at the end of method names follow or detract from normal C# API design?

I know this sounds like a subjective answer, but I will try to make the question as objective as possible, because an objective answer to the question would be the most helpful. I recently had a code reviewer point out that I have a habit of…
Michael Hedgpeth
  • 7,732
  • 10
  • 47
  • 66
12
votes
4 answers

Type inference for fluent API

I have the following extension methods: public static IFoo Foo(this IFluentApi api, Action action); public static IFoo Foo( this IFluentApi api, Func func); public static IBar Bar(this IFoo foo); public static void…
D.R.
  • 20,268
  • 21
  • 102
  • 205
12
votes
3 answers

How to create a fluent query interface?

I know how to chain class methods (with the "return $this" and all), but what i am trying to do is to chain them in a smart way, have a look at this: $albums = $db->select('albums')->where('x', '>', '20')->limit(2)->order('desc'); What i could…
Dewan159
  • 2,984
  • 7
  • 39
  • 43
11
votes
1 answer

Ensuring that a call is made to end a chain of methods

Note/Disclaimer: After a few searches, the nearest thing I have I have seen to this post is a post on SO (Method chaining and the finishing problem) which is similar to my question, but doesn't really answer it - but anyway, I hope this is not a…
Jay
  • 9,561
  • 7
  • 51
  • 72
10
votes
2 answers

Do monads have fluent interfaces?

Forgive me if this question seems stupid, but I'm quite new to the whole world of functional programming so I'll need some denizens on StackOverflow to set me straight. From what I gather, an operation on a monad returns a monad. Does this mean that…
user193476
1 2
3
29 30