Design Pattern Examples
Overview of object-oriented design patterns
Visitor_Exercise Class Reference

Example of using the Visitor Pattern in C#. More...

Collaboration diagram for Visitor_Exercise:
Collaboration graph

Public Member Functions

void Run ()
 Executes the example for the Visitor Pattern in C#.
 

Detailed Description

Example of using the Visitor Pattern in C#.

The Visitor pattern is used to add functionality to a list of otherwise unchanging element objects by passing a visitor object to each element object. Each element object calls the visitor object, passing itself as an argument. The visitor object then does something based on the type of the element.

In this exercise, a collection of shop objects is initialized then an order visitor is created to retrieve an item from one of the shop objects. Along the way, shops that don't have the necessary ingredients use another order visitor to order ingredients from other shops. This approach assumes no two shops sell the same thing.

Definition at line 26 of file Visitor_Exercise.cs.

Member Function Documentation

◆ Run()

void Run ( )
inline

Executes the example for the Visitor Pattern in C#.

Definition at line 32 of file Visitor_Exercise.cs.

References Village.Accept(), OrderVisitor.ItemsReceived, Village.LoadVillage(), Village.Name, and OrderVisitor.ShopNameReceivedFrom.

Referenced by Program.Run().


The documentation for this class was generated from the following file: