双重派遣在访客模式中如何工作? [英] How does double dispatch work in Visitor pattern?

查看:92
本文介绍了双重派遣在访客模式中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究与访问者模式有关的其他问题,但无法理解访客模式中双重调度的实现。

I was looking into other questions related to the visitor pattern but couldn't understand the implementation of double dispatch in visitor pattern.

请参阅链接
访问者模式

双重派遣如何工作在访客模式中

How does double dispatch work in the Visitor pattern?

推荐答案

元素对象的接受方法接收访问者对象,它调用访问对象的访问方法。由于访问者对象有几个访问方法,基于元素类型,调用适当的访问方法。在这里,我们为元素指定了元素操作两个调用(双调度)(根据其类型)。

The element object's accept method receives a visitor object and it calls the visit method on the visitor object. As the visitor object has several visit methods, based on the element type the appropriate visit method is called. Here we have two calls (double dispatch) that specify the element and the right operation for the element (based on its type).

这篇关于双重派遣在访客模式中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆