DEV Community

Discussion on: What the hell is pattern matching?

Collapse
 
nielselgers profile image
Niels Elgers

Cool post, Alex! Learned something new.

I've never encountered this concept before because I tend to always avoid type checking.

In what situations do you use/prefer type checking over avoiding it using e.g. Visitor pattern, pulling up to a common interface, ... ?

Collapse
 
alexdhaenens profile image
Alex Dhaenens

Well it depends (as usual). I prefer type checking when I only need to get some properties (that are not in the common interface). Or, which was the case when I found this feature, there was too much (legacy) code (that is executed based on the concrete business class) that I could not move to another class or place. In any other case I would indeed prefer the Visitor pattern.
Why do you prefer to use the Visitor pattern?