Hacker News new | ask | show | jobs
by scroot 2662 days ago
It does come from Smalltalk, which is in part why it looks so sloppy and strange in other languages (a Ruby example I saw even had an intermediary class for the visitor part, which doesn't really happen in Smalltalk).

The reason to use this pattern is to leverage real polymorphism. In Squeak/Pharo, the graphics system is called Morphic, which uses this pattern all the time to draw different kinds of objects to different kinds of Canvases. With a visitor pattern, each object can "know" how to draw itself to a given canvas.