-
Book Overview & Buying
-
Table Of Contents
Design Patterns and Best Practices in Java
By :
Computers are supposed to interpret sentences or evaluate expressions. If we have to write a sequence of code that is supposed to deal with such a requirement, first of all, we need to know the structure; we need to have an internal representation of the expression or the sentence. In many situations, the most appropriate structure to use is a composite one based on the composite pattern. We will further discuss the composite pattern in Chapter 4, Structural Patterns, for now, we can think of composite representation as grouping objects of a similar nature together.
The interpreter pattern defines the representation of the grammar along with the interpretation.
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...