Re:Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
by yvdriess on Wednesday March 06, 2019 @11:00AM
(#19319872)
I've always heard that pattern itself is older than C++, originating from Smalltalk.
[ Parent
| on HN ]
Re:Grim C++ Tales from the Crypt: The Visitor Pattern (2017)
by scroot on Wednesday March 06, 2019 @12:21PM
(#19320678)
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.