Fluent interfaces and leaky abstractions

前端 未结 8 2228
攒了一身酷
攒了一身酷 2021-02-13 14:30

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, wha

相关标签:
8条回答
  • 2021-02-13 15:21

    An object-oriented interface is fluent if methods that are executed for side effect return self, so that such methods can be chained together.

    I first encountered fluent interfaces in 1990 when the Modula-3 Interface Police (I am not making this up) required all initialization methods to return the object initialized. I believe this usage predates the coinage of the term "fluent interface".

    0 讨论(0)
  • 2021-02-13 15:24

    A leaky abstraction is an abstraction where the details of the underlying reality often "leaks through".

    All abstractions lie more or less, but sometimes the abstraction is such a bad fit to the underlying reality, that it causes more harm than it helps.

    A simple example of a "leak" in an abstraction might be the usual float type. It seems to represent general real numbers and you can use it to perform basic calculations. But at some time you encounter a scenario where 1/3*3 != 1 or 1 + 10^-20 = 1. That is when the actual implementation details leak through and the abstraction breaks.

    0 讨论(0)
提交回复
热议问题