Overview
The Interpreter Design Pattern is used to define a language, its grammar, and syntax in an object-oriented way. It allows us to get code that looks like this:
fromCollection("cities",
select("name",
where(field("population",
lessThan(2000000)))))
Defined objects are then used to interpret custom-defined language in a context. This pattern is especially useful when expressing intent is more readable using natural or custom Domain-Specific Language (DSL). Interpreter Design Pattern uses classes and objects to define grammar and syntax, and optionally it can also include a parser, which allows language to be defined not only as classes and objects but as text which is then converted into classes and objects for evaluation.
More on this pattern…
To read more on this and the other patterns, get “GoF Design Patterns Distilled” book from Amazon or Leanpub: