To explain this pattern, I’m going to jump into an example first and then discuss the pattern itself. Hope you don’t mind! 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 expression can be represented using an object hierarchy similar to the following:
public abstract class Expression { /* nothing here (yet) */ }
public class DoubleExpression : Expression
{
private double ...