I’m really confused about the visitor pattern and its uses. I can’t really seem to visualize the benefits of using this pattern or its purpose. If someone could explain with examples if possible that would be great.
Share
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.
Once upon a time…
Then you realize you’d like to be able to filter the library’s collection by other genres. You could keep adding new getter methods. Or you could use Visitors.
You separate the data from the algorithm. You offload the algorithm to visitor implementations. You add functionality by creating more visitors, instead of constantly modifying (and bloating) the class that holds the data.