previous | start | next

## Visitors

- Problem: Operation may be different for different element types
- Can't rely on polymorphism
- Polymorphism assumes fixed set of methods, defined in superclass
- Trick: Can use variable set of methods if set of classes is fixed
- Supply separate visitor methods:
  public interface Visitor
  {
  void visitElementType1(ElementType1 element);
  void visitElementType2(ElementType2 element);
  ...
  void visitElementTypen(ElementTypen element);
  }

previous | start | next