Enterprise Application Architecture with .NET Core
by Ganesan Senthilvel, Ovais Mehboob Ahmed Khan, Habib Qureshi
The visitor pattern
The visitor pattern allows you to separate an algorithm via the visitor class from an object structure (aggregating elements) so that the new operations can be added without modifying the object structure.
It's a cleaner way by design for an old way of C++ friend class, which is allowed to access the private members of another class.
In simple words, you break the class into two classes, one only with elements/variables, and another only with the methods. In this way, you keep the one with variables the same while varying the methods, that is, algorithms in the other class. You define the methods grouped together in an interface called visitor so that you can have more than one implementation of this visitor interface, ...
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