Chapter 35. Method Chaining
Make modifier methods return the host object, so that multiple modifiers can be invoked in a single expression.
35.1 How It Works
Method Chaining rapidly caught on amongst people as an example of what an internal DSL should look like. It caught on a bit too much—people started to assume that Method Chaining was synonymous with fluent interfaces and internal DSLs. My view is that Method Chaining is one of several techniques, but it’s still valuable and noticeable.
Its common form is on an Expression Builder. Consider the hard drive in the sketch. Using a regular command-query API, I might set it up like this:
I create ...
Get Domain Specific Languages now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.