Chapter 15. Visitor
Imagine you have some plumbing problems in your house but you don't know how to fix them. Even though you are the owner of the house, that doesn't mean you know all the ins and outs of it. Therefore, the most efficient way to solve this problem is to call in an expert to get it fixed as soon as possible.
In software design, a class can become extremely complex if the architect stuffs too many methods into it to extend its functionality. A better approach is to have an external class that knows how to extend it without changing the original code much.
The Visitor pattern can be easily described by using examples from your everyday life. In the case of the household plumbing problem, you don't want to learn how to fix plumbing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access