How does double dispatch work in Visitor pattern?

前端 未结 4 567
北海茫月
北海茫月 2020-12-14 03:18

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

Please refer to

4条回答
  •  伪装坚强ぢ
    2020-12-14 03:39

    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).

提交回复
热议问题