Title :
The essence of the Visitor pattern
Author :
Palsberg, Jens ; Jay, C. Barry
Author_Institution :
Dept. of Comput. Sci., Purdue Univ., West Lafayette, IN, USA
Abstract :
For object-oriented programming, the Visitor pattern enables the definition of a new operation on an object structure without changing the classes of the objects. The price has been that the set of classes must be fixed in advance, and they must each have a so-called accept method. In this paper we demonstrate how to program visitors without relying on accept methods and without knowing all classes of the objects in advance. The idea, derived from related work on shape polymorphism in functional programming, is to separate (1) accessing subobjects, and (2) acting on them. In the object-oriented setting, reflection techniques support access to sub-objects, as demonstrated in our Java class, Walkabout. It supports all visitors as subclasses, and they can be programmed without any further use of reflection. Thus a program using the Visitor pattern can now be understood as a specialized version of a program using the Walkabout class
Keywords :
functional programming; object-oriented programming; Java class; Visitor pattern; Walkabout class; accept methods; functional programming; object-oriented programming; reflection techniques; sub-objects; Australia; Computer science; Electrical capacitance tomography; Functional programming; Ice; Java; Read only memory; Reflection; Writing;
Conference_Titel :
Computer Software and Applications Conference, 1998. COMPSAC '98. Proceedings. The Twenty-Second Annual International
Conference_Location :
Vienna
Print_ISBN :
0-8186-8585-9
DOI :
10.1109/CMPSAC.1998.716629