The Interpreter pattern interprets a language to define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. The following diagram illustrates the Interpreter pattern.
The following lists the benefits of using the Interpreter pattern:
Easy to change and extend the grammar
Implementing the grammar is easy
When to Use:
You should use the Interpreter pattern when:
The grammar of the language is simple.
Efficiency is not a critical concern.
Interpreter Pattern: Useful when the objective is to provide a client program or a user the ability to specify operations in a simple language. Helps in interpreting operations specified using a language, using its grammar. More suitable for languages with simple grammar