Some design patterns just appear weird the first time you come across them. The “Visitor” pattern is like that for me because of all the double dispatch stuff. I understand it and I use it on rare occasions, but I rarely reach for it because I’m not perfectly comfortable with it. Uncle Bob of ObjectMentor has a great post on the Visitor pattern called “I Use Visitor” that’s a good explanation of the pattern. Familiarity with a pattern like Visitor mitigates the weirdness.
It’s timely for me because I have a little side project going that will likely involve a “Composite” pattern that will include multiple operations across the aggregate object graph. I’ll definitely consider a Visitor when I get there.
I used to grade code submissions from job applicants at a former employer. One of the very few good submissions I ever looked at came from a C# coder who used a Visitor pattern on a sales tax calculation problem (think lot’s of exception cases). At first blush I thought it was over-designed, but after a closer look I thought the usage of the Visitor pattern was a fairly elegant way to solve the problem.