Visitor Pattern

Created on 2020-08-27T01:24:06.378963

Return to the Index

This card can also be read via Gemini.

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++.)