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 46. Literal Extension

Add methods to program literals.

 42.grams.flour

46.1 How It Works

Literals, such as numbers and strings, often make a good starting point for DSL expressions. Traditionally, however, they are built-in types with fixed interfaces, so you can’t extend them. More languages now allow you to add methods to third-party classes using techniques like C#’s extension methods and Ruby’s open classes. This capability is particularly handy for DSLs, as it allows you to start a method chain with a literal.

As with most method chains, one important decision is whether to use an Expression Builder. If you don’t use an Expression Builder, you have to ensure that all the intermediate types have the appropriate fluent methods defined ...

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