GofPatterns Gofpatterns





Behavioral Patterns  «Prev  Next»

Interpreter Pattern

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.
Interpreter Pattern contains the TerminalExpression and NonterminalExpression class that inherit from AbstractExpression.
Interpreter Pattern contains the TerminalExpression and NonterminalExpression class that inherit from AbstractExpression.

Interpreter Pattern Java Code


Benefits:
The following lists the benefits of using the Interpreter pattern:
  1. Easy to change and extend the grammar
  2. Implementing the grammar is easy
When to Use:
You should use the Interpreter pattern when:
  1. The grammar of the language is simple.
  2. Efficiency is not a critical concern.