shlogg · Early preview
Maxi Contieri @mcsee1

Avoid Instanceof Checks With Visitor Pattern.

Avoid combining Visitor pattern with instanceof checks, it breaks separation and leads to fragile design. Use polymorphism instead, favor encapsulation and keep code clean & maintainable.

Don't knock. You are accepted

TL;DR: Avoid combining the Visitor pattern with instanceof checks.

  
  
  Problems 😔

Open/Closed principle violation
Tight Coupling
Maintainability
Code duplication
Poor readability
Brittle design
IFs

  
  
  Solutions 😃

Implement the Visitor pattern correctly.
Avoid instanceof checks.
Favor polymorphism.
Encapsulate behavior.

  
  
  Context 💬

When you use the Visitor pattern, you aim to separate algorithms from the objects they operate on.
Combining it with instanceof checks breaks this separation, leading to a fragile and hard-to-maintain design....