The emph{Visitor design pattern allows the encapsulation of polymorphic behavior outside the class hierarchy on which it operates. A common application of emph{Visitor is the encapsulation of tree traversals. Unfortunately, visitors resist composition and allow little traversal control. To remove these limitations, we introduce visitor emph{combinators. These are implementations of the visitor interface that can be used to emph{compose new visitors from given ones. The set of combinators we propose includes emph{traversal combinators that can be used to obtain full traversal control. A clean separation can be made between the generic parts of the combinator set and the parts that are specific to a particular class hierarchy. The generic parts form a reusable framework. The specific parts can be generated from a (tree) grammar. Due to this separation, programming with visitor combinators becomes a form of emph{generic programming with significant reuse of (visitor) code.

, , , , ,
CWI
Software Engineering [SEN]

Visser, J. (2001). Visitor combination and traversal control. Software Engineering [SEN]. CWI.