Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 536
GurdeepS Avatar asked Jan 11 '09 19:01

GurdeepS


People also ask

What is meant by leaky abstraction?

In software development, a leaky abstraction is an abstraction that leaks details that it is supposed to abstract away. As coined by Joel Spolsky, the Law of Leaky Abstractions states: All non-trivial abstractions, to some degree, are leaky.

What is abstraction stack overflow?

Quite simply, abstraction is the art of limiting your dependencies. The less you depend on, the more abstract you are. For example, if you write a DirectX renderer, then you're abstracted from what graphics card vendor and model you're running on.


1 Answers

A fluent interface is an API that allows you to write code that reads more or less like normal English. For example:

Find.All.Questions(Where.IsAnswered == true);

Method-chaining is usually used as part of the implementation, but there is more to it than that. To quote Fowler:

I've also noticed a common misconception - many people seem to equate fluent interfaces with Method Chaining. Certainly chaining is a common technique to use with fluent interfaces, but true fluency is much more than that.

It is also often called an internal DSL, since the syntax resembles that of a DSL, but it is implemented inside the host language instead of being processed by a parser.

like image 135
Rasmus Faber Avatar answered Oct 04 '22 19:10

Rasmus Faber