O'Reilly logo

Domain Specific Languages by Martin Fowler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 35. Method Chaining

Make modifier methods return the host object, so that multiple modifiers can be invoked in a single expression.

image

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required