The essence of the Visitor pattern

The essence of the Visitor pattern
复制标题

访客模式的本质

DOI:
--
复制
发表时间:
1998
期刊:
Annual International Computer Software and Applications Conference
影响因子:
--
通讯作者:
C. Jay
C. Jay
中科院分区:
--
文献类型:
--
作者:
J. Palsberg;C. Jay

文献摘要

被引文献

相似文献

对于面向对象的编程,访问者模式可以定义对象结构上的新操作,而无需更改对象的类别。价格是必须提前确定一组类,并且他们必须每个人都有一种所谓的接受方法。在本文中,我们演示了如何在不依赖接受方法的情况下对访问者进行编程,而不必事先知道所有级别的对象。这个想法来自功能编程中的相关工作,是为了分开(1)访问子对象,以及(2)对它们进行作用。在面向对象的设置中,反射技术支持对亚物体的访问,如我们的Java类Walkabout所示。它支持所有访问者作为子类,并且可以在不进一步使用反射的情况下进行编程。因此,使用访问者模式的程序现在可以被理解为使用Walkabout类的程序的专业版本。
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.