3 ms·
More generally, the visitor pattern is an example of double dispatch, where the concrete implementation of a function varies on the type of two parameters to th
by hnov 11y ago
More generally, the visitor pattern is an example of double dispatch, where the concrete implementation of a function varies on the type of two parameters to the function. I'm not sure that there's any real difference in the implementation of the visitor pattern that arises from static vs dynamic typing. Just like in ruby, in a language like java you could have a cascade of if/elses that type check the second parameter (or the first one for that matter, OO is really just a way to have a case statement that isn't centralized in one place in source code).
- vidarh 11y agoBut in the GoF visitor pattern, the "case statement" is in fact centralized in one place: In the class implementing the visitor. And of course you can have the equivalent in C++/Java and similar languages, but that would lose the main benefit of having the completeness of the visitor statically checked (In other words, you can write dynamically typed code in any language some way or the).