© Vaskaran Sarcar 2018
V. SarcarDesign Patterns in C#https://doi.org/10.1007/978-1-4842-3640-6_13

13. Visitor Pattern

Vaskaran Sarcar1  
(1)
Whitefield, Bangalore, Karnataka, India
 

This chapter covers the Visitor pattern.

GoF Definition

Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

Concept

With this pattern, you separate an algorithm from an object structure. So, you can add new operations without modifying the existing architecture. This pattern supports the open/close principle (which says extension is allowed but modification is disallowed for entities such as class, function, modules, and so on).

Note

You can experience ...

Get Design Patterns in C#: A Hands-on Guide with Real-World Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.