jargon

Comparison

Builder patternvsFluent interface

Builder pattern

you set five things by name across five lines and call build, and the object does not exist until the last one.

Separating the construction of a complex object from its representation, so the object is assembled step by step and only produced when complete. Two distinct motivations get the same name: making a long parameter list readable, and letting one construction process produce different representations. Its underrated benefit is that the built object can be immutable and fully validated, because there is no half-built instance for anyone to see.

Full entry →

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 →

Related comparisons