Problems with the Visitor Pattern #421
sergioantoy
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problems: (1) the code presented to explain the Visitor Pattern is missing a test or an example of execution. (2) the type Expr in the presented code is ideal for applying the pattern, but no visitor is shown and used. (3) no compelling reason is given for the need of a visitor.
The pattern allows adding new virtual-like functions to a family of classes, without modifying the classes. This is non-trivial in languages like C++ and Java in which classes are closed. In rust adding functionality to a type (or hierarchy of types) does not require modifying the type (or the hierarchy).
Below is a definition of a simple arithmetic expression type (hierarchy) and two operations on it that are defined without modifying the type. This example suggests that the Visitor Pattern is not useful in Rust.
Beta Was this translation helpful? Give feedback.
All reactions