Design Pattern Examples
Overview of object-oriented design patterns
Visitor_Village.cs
Go to the documentation of this file.
1
5
6using System.Collections.Generic;
7
9{
17 {
21 public string Name = string.Empty;
22
26 private List<Visitor_Shop> shops = new List<Visitor_Shop>();
27
31 public void LoadVillage()
32 {
33 Name = "Village of Self-Sufficiency";
34
36 {
37 Name = "Joe's Burger Joint",
38 Address = "47 Millings Rd.",
39 Village = this,
40 IngredientsForItems = new Dictionary<string, string[]> {
41 { "hamburger", new string[] { "ground beef", "hamburger buns", "ketchup", "mustard", "mayonnaise", "lettuce", "tomato", "onion", "pickles" } }
42 }
43 });
44
46 {
47 Name = "Amelia's Butcher Shop",
48 Address = "12 Klaxon Ave.",
49 Village = this,
50 IngredientsForItems = new Dictionary<string, string[]> { { "ground beef", new string[] { } } }
51 });
52
53 shops.Add(new Visitor_Baker
54 {
55 Name = "Oxel's Breads and Buns Bakery",
56 Address = "131 Worthington Dr.",
57 Village = this,
58 IngredientsForItems = new Dictionary<string, string[]> { { "hamburger buns", new string[] { } } }
59 });
60
62 {
63 Name = "Connie's Condiments",
64 Address = "83 Millings Rd.",
65 Village = this,
66 IngredientsForItems = new Dictionary<string, string[]> {
67 { "ketchup", new string[] { "fresh ketchup" } },
68 { "mustard", new string[] { "fresh mustard" } },
69 { "mayonnaise", new string[] { "fresh mayonnaise" } }
70 }
71 });
72
74 {
75 Name = "Florence's Vegetables",
76 Address = "32 Main St.",
77 Village = this,
78 IngredientsForItems = new Dictionary<string, string[]> {
79 { "lettuce", new string[] { } },
80 { "tomato", new string[] { } },
81 { "onion", new string[] { } },
82 { "cucumber", new string[] { } },
83 { "mustard seed", new string[] { } }
84 }
85 });
86
88 {
89 Name = "Larry's Pickle Emporium",
90 Address = "34 Main St.",
91 Village = this,
92 IngredientsForItems = new Dictionary<string, string[]> { { "pickles", new string[] { "vinegar", "cucumber", "salt" } } }
93 });
94
95 shops.Add(new Visitor_Maker
96 {
97 Name = "Klyde and Sons Ketchup Makers",
98 Address = "800 Overtown Rd.",
99 Village = this,
100 IngredientsForItems = new Dictionary<string, string[]> { { "fresh ketchup", new string[] { } } }
101 });
102
103 shops.Add(new Visitor_Maker
104 {
105 Name = "Molly's Mustard Mart",
106 Address = "810 Overtown Rd.",
107 Village = this,
108 IngredientsForItems = new Dictionary<string, string[]> { { "fresh mustard", new string[] { "vinegar", "mustard seed" } } }
109 });
110
111 shops.Add(new Visitor_Maker
112 {
113 Name = "Turk's Mayo Supply",
114 Address = "820 Overtown Rd.",
115 Village = this,
116 IngredientsForItems = new Dictionary<string, string[]> { { "fresh mayonnaise", new string[] { } } }
117 });
118
119 shops.Add(new Visitor_Maker
120 {
121 Name = "Vinnies' Sour Flavors",
122 Address = "830 Overtown Rd.",
123 Village = this,
124 IngredientsForItems = new Dictionary<string, string[]> { { "vinegar", new string[] { } } }
125 });
126
127 shops.Add(new Visitor_Maker
128 {
129 Name = "Jessie's Salt Works",
130 Address = "920 Overtown Rd.",
131 Village = this,
132 IngredientsForItems = new Dictionary<string, string[]> { { "salt", new string[] { } } }
133 });
134 }
135
136
137 // Implementation of the ISupportVisitors interface.
138 public void Accept(Visitor visitor)
139 {
140 foreach (var shop in shops)
141 {
142 shop.Accept(visitor);
143 }
144 }
145 }
146}
Represents a collection of shops that can be visited.
void LoadVillage()
Load the village.
List< Visitor_Shop > shops
List of Visitor_Shop class-derived shops in this village that can be visited.
string Name
Name of this village.
void Accept(Visitor visitor)
The visitor will call this method on each element it wants to visit.
All visitors must implement this base class and then override one or more of the VisitXXX() methods,...
The interface that all element classes must implement if they are to participate in the visitor patte...
The namespace containing all Design Pattern Examples implemented in C#.