An Interpreter Pattern says that "to define a representation of grammar of a given language, along with an interpreter that uses this representation to interpret sentences in the language".
Basically the Interpreter pattern has limited area where it can be applied. We can discuss the Interpreter pattern only in terms of formal grammars but in this area there are better solutions that is why it is not frequently used.
This pattern can applied for parsing the expressions defined in simple grammars and sometimes in simple rule engines.
SQL Parsing uses interpreter design pattern.
Advantage of Interpreter Pattern
Usage of Interpreter pattern:
It is used:
Example of Interpreter Pattern
Let's understand the example of Interpreter Pattern by the above UML diagram.
UML for Interpreter Pattern:
Implementation of above UML
Create a Pattern interface.
Create a InfixToPostfixPattern class that will allow what kind of pattern you want to convert.
Create a InterpreterPatternClient class that will use InfixToPostfix Conversion.