News for hackers. Stuff that matters.
Re:Software Design Patterns Are Not Goals, They Are Tools by munificent on Thursday May 19, 2016 @01:50PM (#11732117)
That's actually not what the visitor pattern is about, though the way it's typically presented and the poor name tends to confuse the fact. Visitor isn't about traversing trees. It's about letting you define class-specific behavior outside of the definition of the class itself.

It gives you a way to "add a method" to a set of classes without actually stuffing them in the class definitions themselves.

In practice, most visitor patterns are used with AST classes or other types that are stored in a tree-like fashion, but that's coincidence. The visitor pattern itself is really about using virtual dispatch to avoid an ugly and non-type-safe type switch.

Re:Software Design Patterns Are Not Goals, They Are Tools by emodendroket on Friday May 20, 2016 @09:07AM (#11737432)
I'm not sure I'm following what you describe. Like an extension method or mix-in?
Re:Software Design Patterns Are Not Goals, They Are Tools by Munksgaard on Friday May 20, 2016 @03:15AM (#11736035)
So pattern matching?
Re:Software Design Patterns Are Not Goals, They Are Tools by munificent on Wednesday May 25, 2016 @01:30AM (#11767832)
Sort of. It's a way to emulate a simple subset of pattern matching in languages that lack it.