Interpreter PatternAn 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 PatternLet's understand the example of Interpreter Pattern by the above UML diagram. UML for Interpreter Pattern:Implementation of above UMLStep 1Create a Pattern interface. Step 2Create a InfixToPostfixPattern class that will allow what kind of pattern you want to convert. File: InfixToPostfixPattern.java Step 3Create a InterpreterPatternClient class that will use InfixToPostfix Conversion. File: InterpreterPatternClient.java OutputNext TopicIterator Design Pattern in Java |