Adib Faramarzi
Oct 20, 2023

--

Sure!

When we are using the "sealed class" method, inside the switch-case expression we only have access to the object's public fields (like box.weight() and so on), so if we prefer to hide the weight() function, we can do that in the visitor pattern by making the visit(Box) function to visitBoxWeight(int) function. This makes the Box class's visit to call this function by visit(this.weight()) and hide the weight() functionality.

I hope that helped 😉

--

--

Adib Faramarzi
Adib Faramarzi

Written by Adib Faramarzi

Senior Android Manager / Head of Mobile at TAPSI

No responses yet