Fluent interface

In software engineering, a fluent interface is an object-oriented API whose design relies extensively on method chaining.

A common example is the iostream library in C++, which uses the << or >> operators for the message passing, sending multiple data to the same object and allowing "manipulators" for other method calls.

In the Java Swing API, the LayoutManager interface defines how Container objects can have controlled Component placement.

Typically, fluent builders are used to implement "database queries", for example in the Dynamite client library: A simple way to do this in JavaScript is using prototype inheritance and this.

Scala supports a fluent syntax for both method calls and class mixins, using traits and the with keyword.

It is however discouraged by the language’s creator, Guido van Rossum,[3] and therefore considered unpythonic (not idiomatic) for operations that do not return new values.

Van Rossum provides string processing operations as example where he sees the fluent pattern appropriate.

E.g., given: To log the state of buffer after the rewind() method call, it is necessary to break the fluent calls: This can be worked around in languages that support extension methods by defining a new extension to wrap the desired logging functionality, for example in C# (using the same Java ByteBuffer example as above): Subclasses in strongly typed languages (C++, Java, C#, etc.)

often have to override all methods from their superclass that participate in a fluent interface in order to change their return type.