访问者在 TypeScript 中的实现
Visitor is a behavioral design pattern that allows adding new behaviors to existing class hierarchy without altering any existing code.
Read why Visitors can't be simply replaced with method overloading in our article Visitor and Double Dispatch.
在 TypeScript 中使用模式
Usage examples: Visitor isn't a very common pattern because of its complexity and narrow applicability.
This example illustrates the structure of the Visitor design pattern. It focuses on answering these questions:
- What classes does it consist of?
- What roles do these classes play?
- In what way the elements of the pattern are related?
index.ts: Conceptual Example
Output.txt: Execution result