Refactoring Example: Switch to Visitor
If you’ve ever wanted a virtual method in a class hierarchy, but found there was something stopping you, this video is for you.
The Visitor Pattern allows developers to add polymorphic behavior to a class hierarchy without modifying the hierarchy itself.
A common response to the absence of the Visitor Pattern when it is called for is to use switch statements to create variable behavior in various places. This creates a huge burden of technical debt because you have to chase down every switch statement and maintain it whenever something about the hierarchy changes.
In this video, you will learn about the motivation behind the Visitor Pattern, why you should avoid using switch statements to solve the problem it solves, and how to transform a switch statement into a clean implementation of the Visitor Pattern.