首页> 外国专利> Extensible and efficient double dispatch in single-dispatch object-oriented programming languages

Extensible and efficient double dispatch in single-dispatch object-oriented programming languages

机译:单调度面向对象编程语言中可扩展且高效的双调度

摘要

An improved method and system is described for implementing double dispatch extensibly and efficiently in single-dispatch object-oriented programming languages. Objects of type Visitor encapsulate double dispatch functionality, while objects of type Element act as operands. Double dispatch takes place by calling Accept on an object of type Element, passing an object of type Visitor as an argument. Concrete classes of type Element are added in groups, each group deriving from an abstract subclass of Element. An AbstractElement class augments the Element interface with an Accept operation that takes an object of type AppVisitor as an argument, where AppVisitor is an abstract subclass of Visitor. AppVisitor overrides the base class Visit operation to test the type of its Element argument, casting it into an AppElement and calling its augmented Accept. By committing to a client-specific AppVisitor interface as deeply in the Visitor class hierarchy as possible, the set of concrete element subclasses may be extended without changing the Visitor base class. Clients that rely on double dispatch are thus unaffected by such extension. Moreover, by calling the AbstractElement-augmented Accept rather than performing more extensive type tests for concrete Element subclasses, running time is improved over approaches that rely on more extensive type testing. Default functionality is easily accommodated as well.
机译:描述了一种改进的方法和系统,该方法和系统用于在单调度面向对象的编程语言中扩展且有效地实现双调度。类型为Visitor的对象封装了双重调度功能,而类型为Element的对象充当操作数。通过在Element类型的对象上调用Accept,并将Visitor类型的对象作为参数传递,可以进行双重调度。成组添加类型为Element的具体类,每个组派生自Element的抽象子类。 AbstractElement类通过接受操作扩展了Element接口,该操作将AppVisitor类型的对象作为参数,其中AppVisitor是Visitor的抽象子类。 AppVisitor重写基类Visit操作以测试其Element参数的类型,将其强制转换为AppElement并调用其增强的Accept。通过尽可能深入地访问访客类层次结构中的特定于客户的AppVisitor接口,可以扩展具体元素子类集,而无需更改访客基类。因此,依赖双重调度的客户不受这种扩展的影响。而且,通过调用AbstractElement-augmented Accept而不是对具体的Element子类执行更广泛的类型测试,与依赖更广泛的类型测试的方法相比,运行时间得以缩短。默认功能也很容易使用。

著录项

相似文献

  • 专利
  • 外文文献
  • 中文文献
获取专利

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号