Design Patterns · Senior · Question 43 of 75
When is the Visitor pattern justified in a TypeScript project?
- ✓Correct answer: When node types are stable but operations keep growing
- 2When node types change every week and there's one operation
- 3When you need to guarantee a single instance of a class
Explanation
Visitor is handy for ASTs, documents and editor block trees: new operations (rendering, export, validation) are added without changing the nodes. If new nodes are added often, every visitor has to change - that's the expression problem.