Expression Builder

An object, or family of objects, that provides a fluent interface over a normal command-query API.

APIs are usually designed to provide a set of self-standing methods on objects. Ideally, these methods can be understood individually. I call this style of API a command-query API ; it's so normal that we don't have a general name for it. DSLs require a different kind of API, what I call a fluent interface , which is designed with the goal of readability of a whole expression. Fluent interfaces lead to methods that make little sense individually, and often violate the rules for good command-query APIs.

An Expression Builder provides a fluent interface as a separate layer on top of a regular API. This way you have both styles of interface and the fluent interface is clearly isolated, making it easier to follow.

For more information see chapter 32 of the DSL book. There is also a brief discussion on my bliki.

| Catalog of DSL patterns |