skip to Main Content


Say hello to the toggle bar. This is an optional section you can use to display any content you'd like. Simply select a page from the theme panel and the content of the page will display here. You can even use the drag and drop builder to create this! This is a perfect place for your company mission statement, alerts, notices or anything else.

Get In Touch

Phone: 1-800-Total-Theme
Address: Las Vegas, Nevada

Our Location


Visitor Pattern

Post Series: Behavioral Design Pattern

This pattern is used to create and perform new operations onto a set of objects without changing the object structure or classes. This pattern enables loose coupling and addition of new operations without changing the existing structure.

Visitor Design Pattern C#

  • Client: This is a class that has access to the data structure objects and can instruct them to accept a Visitor to perform the appropriate operations.
  • ObjectStructure: This is class that holds all the elements which can be used by visitors.
  • Element: This is an interface that specify the Accept operation.
  • ConcreteElementA/B: These are classes which implement the Element interface and holds the real information.
  • Visitor: This is an interface that specify the Visit operations for concrete visitors.
  • ConcreteVisitorA/B: These are sub classes which implement the Visitor interface.



Có thể thấy, việc thêm một Monster mới rất đơn giản, chỉ cần implement các method của Monster thôi. Trong khi, nếu thêm Human thì ta phải thay đổi cả interface Monster và cập nhật các class implement của Monster.

Chính vì vậy, tùy vào trường hợp cụ thể, xem các đối tượng thuộc loại nào hay bị thay đổi mà cài đặt Visitor Patern cho phù hợp.

When to use it?

  1. An object structure has many unrelated operations to perform on it.
  2. An object structure cannot change but you need to perform new operations on it.
  3. The operations need to perform on the concrete classes of an object structure.


Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top