J
Joshua Cranmer
That's what i'd usually do. But thinking about it, i don't see why it's
preferable to my hypothetical class switch. What's the benefit? How does
using a visitor rather than a switch help me deliver more value to my
customer?
The visitor case is a poor man's implementation of double dispatch (I
meant this earlier when I said "dynamic dispatch"... I suppose 7 PM is
not the time to be rebutting posts...).
That has got to be the fastest abandonment of the technical high ground
i have ever seen. Did you use a sledge?
The real answer to a switch-based-on-class, I think, would be double
dispatch. However, Java doesn't really support double dispatch, and I'm
not sure whether or not it should.
It's mostly a contrived example. I mean, we do actually have some logic
almost exactly like that, but we recognise it's a mistake and are
working on getting rid of it!
I'll grant you that it is a contrived example, but one would hope that a
contrived example would be more persuasive in explaining why a feature
would be useful...
Duff's device!
Hmm, I should put that on a test and ask people what it does and why it
works. I wonder if the average on that question would be above or below 25%.