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 the link
Visitor Pattern
How does double dispatch work in the Visitor pattern?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The element object’s
acceptmethod receives a visitor object and it calls thevisitmethod on the visitor object. As the visitor object has severalvisitmethods, based on the element type the appropriatevisitmethod is called. Here we have two calls (double dispatch) that specify the element and the right operation for the element (based on its type).