Visitor Pattern
Created on 2020-08-27T01:24:06.378963
- #accept accepts the visitor object and calls a visitor on it.
- #visit is implemented by visitors to react to particular nodes.
For example at the top of a tree you would call Tree>>#accept and pass some TreeVisitor. Then if the node is a PotatoNode, it will turn around and call Visitor>>#visitPotato. A tomato would call Visitor>>#visitTomato.
Primarily used in Smalltalk where you need to walk a tree, but the type system is very liberal and you should put type-specific behaviors in the type itself and not from an external dispatcher (as in C++.)