b => "First byte after rewind is " + b.Get(0) ) .Limit(100); Subclasses 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. For example: class A { public A doThis() { ... } } class B extends A{ public B doThis() { super.doThis(); return this; } // Must change return type to B. public B doThat() { ... } } ... A a = new B().doThat().doThis(); // This would work even without overriding A.doThis(). B b = new B().doThis().doThat(); // This would fail if A.doThis() wasn't overridden. Languages that are capable of expressing F-bound polymorphism can use it to avoid this difficulty. For example: abstract class AbstractA<T extends AbstractA<T>> { @SuppressWarnings("unchecked") public T doThis() { ...; return (T)this; } } class A extends AbstractA<A> {} class B extends AbstractA<B> { public B doThat() { ...; return this; } } ... B b = new B().doThis().doThat(); // Works! A a = new A().doThis(); // Also works. Note that in order to be able to create instances of the parent class, we had to split it into two classes — AbstractA and A, the latter with no content (it would only contain constructors if those were needed). The approach can easily be extended if we want to have sub-subclasses (etc.) too: abstract class AbstractB<T extends AbstractB<T>> extends AbstractA<T> { @SuppressWarnings("unchecked") public T doThat() { ...; return (T)this; } } class B extends AbstractB<B> {} abstract class AbstractC<T extends AbstractC<T>> extends AbstractB<T> { @SuppressWarnings("unchecked") public T foo() { ...; return (T)this; } } class C extends AbstractC<C> {} ... C c = new C().doThis().doThat().foo(); // Works! B b = new B().doThis().doThat(); // Still works.In a dependently typed language, e.g. Scala, methods can also be explicitly defined as always returning this and thus can be defined only once for subclasses to take advantage of the fluent interface:class A { def doThis(): this.type = { ... } // returns this, and always this. } class B extends A{ // No override needed! def doThat(): this.type = { ... } } ... val a: A = new B().doThat().doThis(); // Chaining works in both directions. val b: B = new B().doThis().doThat(); // And, both method chains result in a B! See also Command-query separation Method chaining Named parameter Pipeline (Unix) References External links Martin Fowler's