问题描述
我正在研究与访问者模式有关的其他问题,但无法理解访客模式中双重调度的实现。
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).
这篇关于双重派遣在访客模式中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!