Interpreter Design pattern

Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
-GOF Design Pattern

Interpreter design pattern allows you to interpret an expression language in the programming to define a representation for its grammar. This type of a pattern comes under the Behavioral design pattern family of GOF patterns.

The following lists the benefits of using the Interpreter pattern:

  • This pattern allows you to change and extend the grammar easily.
  • Using the expression language is very easy

Let's see the following UML diagram is showing all components of Interpreter design pattern:

UML diagram for Interpreter design pattern
  • AbstractExpression: It is an interface to execute a task by using interpret() operation.
  • TerminalExpression: It is an implementation of above interface and it implements interpret() operation for terminal expressions.
  • NonterminalExpression: It is also an implementation of above interface and it implements interpret() operation for non-terminal expressions.
  • Context: It is a String expression and contains information that is global to the interpreter.
  • Client: It is the main class to invoke the Interpret operation.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset