The interpreter pattern uses the composite pattern to define the internal representation of the object structure. In addition to that, it adds the implementation to interpret an expression and to convert it to the internal structure. For this reason, the interpreter pattern falls within the behavioral patterns category. The class diagram is as follows:

The interpreter pattern is composed of the following classes:

  • Context: This is used to encapsulate the information that is global to the interpreter and needs to be accessed by all concrete interpreters.
  • AbstractExpression: An abstract class or interface that declares the interpret ...

Get Design Patterns and Best Practices in Java now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.