Design Patterns Interpreter Pattern - Design Patterns

What is Design Pattern Interpreter Pattern?

Interpreter pattern provides a way to evaluate language grammar or expression. This type of pattern comes below behavioural pattern. This pattern involves implementing an expression interface which tells to understand an exacting context. This pattern is used in SQL parsing, symbol giving out device etc.

Implementation

We are going to produce an interface Expression and concrete classes implementing the Expression interface. A class Terminal Expression is define which acts as a main interpreter of context in question. Other classes Or Expression, And Expression are used to make combinational language.

InterpreterPatternDemo, our demo class, will use Expression class to create rules and display parsing of terms.
interpreter_pattern_uml_diagram

Step 1

Create an expression interface.

Expression.java

Step 2

Create concrete classes implementing the above interface.

TerminalExpression.java

OrExpression.java

AndExpression.java

Step 3

InterpreterPatternDemo uses Expression class to produce rules and then parse them.

InterpreterPatternDemo.java

Step 4

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics