Comparison
Fluent interfacevsMessage chain
Fluent interface
every method returns the object again, so the calls chain into something that reads almost like a sentence.
An API designed for chained calls, where each method returns a receiver so the next call can follow. It is what most builders look like, and it is also used well beyond construction — query builders, assertion libraries, configuration. The costs are real and usually unmentioned: chained calls are awkward to debug, hard to break across a conditional, and confusing when the interface mixes mutating and copying steps.
Full entry →Message chain
the line is four dots long and a change to any object along the way breaks the code at the end of it.
Navigating through a chain of objects to reach the one you actually want, which couples the caller to every structure along the path. It is the violation the Law of Demeter names, and the standard fix is to ask the nearest object for what you need so the traversal happens where the structure is known. Fluent interfaces look identical and are not the same thing — each call there returns the same receiver by design.
Full entry →