To explain this pattern I’m going to jump into an example first and then discuss the pattern itself. Suppose you have parsed a mathematical expression (with the use of the Interpreter pattern, of course) composed of
double values and addition operators; for example,
This can expressed using an object hierarchy similar to the following:
public abstract class Expression { /* nothing here (yet) */ }
public class DoubleExpression : Expression
{
private double value;
public DoubleExpression(double value) { this.value = value; }
}
public class AdditionExpression ...