© Dmitri Nesteruk 2019
Dmitri NesterukDesign Patterns in .NEThttps://doi.org/10.1007/978-1-4842-4366-4_25

25. Visitor

Dmitri Nesteruk1 
(1)
St. Petersburg, c.St-Peterburg, Russia
 
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,
(1.0 + (2.0 + 3.0))
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 ...

Get Design Patterns in .NET: Reusable Approaches in C# and F# for Object-Oriented Software Design now with O’Reilly online learning.

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