Tech Tradeoff: Visitor pattern

Tags: software

Refactoring guru: Visitor Pattern

Params

We would weigh the following things.

Approaches

⚖️ Approach 1: Add a method to the Base class

Add a method exportToXML to the Base class.

Cost:

Benefit:

⚖️ Approach 2: Make a use-case specific function

Here our use-case is to exportToXML and so we would make such a function. The function would take a root node which has all the children nested inside it.

Cost:

Benefit:

⚖️ Approach 3: Apply visitor pattern

The visitor pattern is almost similar to approach 2 but has some costs and benefits.

Cost:

Benefit:

Conclusion