Design Pattern Examples
Overview of object-oriented design patterns
visitor_village.py
Go to the documentation of this file.
6
7from .visitor_class import Visitor
8from .visitor_element_classes import *
9
10
15
16
18
19
20 @property
21 def Name(self) -> str:
22 return self._name
23
24
25 @Name.setter
26 def Name(self, value) -> None:
27 self._name = value
28
29
30
31
32
33 def __init__(self) -> None:
34 self._shops = [] # type: list[Visitor_Shop]
35 self._name = ""
36
37
45
46
48 def LoadVillage(self) -> None:
49 self._name = "Village of Self-Sufficiency"
50
51 self._shops.append(Visitor_Restaurant())
52 shop = self._shops[-1]
53 shop.Name = "Joe's Burger Joint"
54 shop.Address = "47 Millings Rd."
55 shop.Village = self
56 shop.IngredientsForItems = {
57 "hamburger": [ "ground beef", "hamburger buns", "ketchup", "mustard", "mayonnaise", "lettuce", "tomato", "onion", "pickles" ]
58 }
59
60 self._shops.append(Visitor_Butcher())
61 shop = self._shops[-1]
62 shop.Name = "Amelia's Butcher Shop"
63 shop.Address = "12 Klaxon Ave."
64 shop.Village = self
65 shop.IngredientsForItems = {
66 "ground beef" : []
67 }
68
69 self._shops.append(Visitor_Baker())
70 shop = self._shops[-1]
71 shop.Name = "Oxel's Breads and Buns Bakery"
72 shop.Address = "131 Worthington Dr."
73 shop.Village = self
74 shop.IngredientsForItems = {
75 "hamburger buns" : []
76 }
77
78 self._shops.append(Visitor_CondimentGrocer())
79 shop = self._shops[-1]
80 shop.Name = "Connie's Condiments"
81 shop.Address = "83 Millings Rd."
82 shop.Village = self
83 shop.IngredientsForItems = {
84 "ketchup" : [ "fresh ketchup" ],
85 "mustard" : [ "fresh mustard" ],
86 "mayonnaise" : [ "fresh mayonnaise" ]
87 }
88
89 self._shops.append(Visitor_VegetableGrocer())
90 shop = self._shops[-1]
91 shop.Name = "Florence's Vegetables"
92 shop.Address = "32 Main St."
93 shop.Village = self
94 shop.IngredientsForItems = {
95 "lettuce" : [],
96 "tomato" : [],
97 "onion" : [],
98 "cucumber" : [],
99 "mustard seed" : []
100 }
101
102 self._shops.append(Visitor_PickleGrocer())
103 shop = self._shops[-1]
104 shop.Name = "Larry's Pickle Emporium"
105 shop.Address = "34 Main St."
106 shop.Village = self
107 shop.IngredientsForItems = {
108 "pickles" : [ "vinegar", "cucumber", "salt" ]
109 }
110
111 self._shops.append(Visitor_Maker())
112 shop = self._shops[-1]
113 shop.Name = "Klyde and Sons Ketchup Makers"
114 shop.Address = "800 Overtown Rd."
115 shop.Village = self
116 shop.IngredientsForItems = {
117 "fresh ketchup" : []
118 }
119
120 self._shops.append(Visitor_Maker())
121 shop = self._shops[-1]
122 shop.Name = "Molly's Mustard Mart"
123 shop.Address = "810 Overtown Rd."
124 shop.Village = self
125 shop.IngredientsForItems = {
126 "fresh mustard" : [ "vinegar", "mustard seed" ]
127 }
128
129 self._shops.append(Visitor_Maker())
130 shop = self._shops[-1]
131 shop.Name = "Turk's Mayo Supply"
132 shop.Address = "820 Overtown Rd."
133 shop.Village = self
134 shop.IngredientsForItems = {
135 "fresh mayonnaise" : []
136 }
137
138 self._shops.append(Visitor_Maker())
139 shop = self._shops[-1]
140 shop.Name = "Vinnies' Sour Flavors"
141 shop.Address = "830 Overtown Rd."
142 shop.Village = self
143 shop.IngredientsForItems = {
144 "vinegar" : []
145 }
146
147 self._shops.append(Visitor_Maker())
148 shop = self._shops[-1]
149 shop.Name = "Jessie's Salt Works"
150 shop.Address = "920 Overtown Rd."
151 shop.Village = self
152 shop.IngredientsForItems = {
153 "salt" : []
154 }
155
156
157 def Accept(self, visitor : Visitor) -> None:
158 for shop in self._shops:
159 shop.Accept(visitor)
Represents a collection of shops that can be visited.
None Accept(self, Visitor visitor)
Accept a visitor and send them around to all the shops.
_shops
List of shops in this village (filled in by the LoadVillage() method)
_name
Name of this village (set by the LoadVillage() method)
str Name(self)
Property getter for the name of this village: value = o.Name