Timeline for Does the visitor pattern prevent the need to modify existing code when adding new data types?
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 7, 2020 at 23:11 | comment | added | Christophe | @Chethan indeed I was not sure it’s the visitor is the best way for this kind of problems, especially if you add new types. An interpreter pattern seems more appropriate for run-time defined expressions, and an ASN tree traversal likewise. But as it is, the problem is too general to recommend a best approach. | |
Jun 7, 2020 at 18:07 | comment | added | Chethan | @Christophe After going through GoF book or wikipedia, it seemed to me that, for a language such as Java, visit/accept were unnecessary (A prettyprint class could simply traverse an ASN tree and print (referring to GoF example)), unless the traversal itself was nontrivial and was subject to change. Is that what you mean in above comment? | |
Jan 10, 2020 at 22:46 | vote | accept | DylanSp | ||
Jan 9, 2020 at 23:20 | comment | added | Christophe | @DylanSp I understand the simplification. I just wanted to draw the attention that the simplification might end in unproductive flamewars that do not help to advance software engineering ;-) I think the visitor is a very specialised pattern that only has advantage for some very specialized cases and for very complex structures. In many cases, you can opt for iterators and use a map-reduce style (see algorithm, numeric and iterator libraries of C++ that are heavily used in conjunction with lambda functions). Out of curiosity, how would you categorize Ocaml ? | |
Jan 9, 2020 at 21:10 | comment | added | DylanSp | And yeah, OOP vs. FP is an oversimplification, but it's easier to say than "language with subtypes and inheritance" vs. "language with algebraic data types and pattern matching", which are the features that matter here. | |
Jan 9, 2020 at 21:09 | comment | added | DylanSp | Thanks; good to know I have the right idea. I guess the main benefit is just that it allows that tradeoff, if you're constrained to working in an OOP language? | |
Jan 9, 2020 at 19:48 | history | answered | Christophe | CC BY-SA 4.0 |