Design Pattern Examples
Overview of object-oriented design patterns
Visitor_Element_Classes.h
Go to the documentation of this file.
1
5
6#pragma once
7#ifndef __VISITOR_ELEMENT_CLASSES_H__
8#define __VISITOR_ELEMENT_CLASSES_H__
9
10#include <string>
11#include <map>
12#include <memory>
13
14#include "helpers/stringlist.h"
15
16#include "Visitor_Shop.h"
17
19{
20 class Visitor_Restaurant; // forward declaration
21 class Visitor_Butcher; // forward declaration
22 class Visitor_Baker; // forward declaration
23 class Visitor_VegetableGrocer; // forward declaration
24 class Visitor_CondimentGrocer; // forward declaration
25 class Visitor_PickleGrocer; // forward declaration
26 class Visitor_Maker; // forward declaration
27
38 class Visitor
39 {
40 public:
45 virtual void VisitRestaurant(Visitor_Restaurant* shop) { (void)shop; /* unused */ }
46
51 virtual void VisitButcher(Visitor_Butcher* shop) { (void)shop; /* unused */ }
52
57 virtual void VisitBaker(Visitor_Baker* shop) { (void)shop; /* unused */ }
58
63 virtual void VisitVegetableGrocer(Visitor_VegetableGrocer* shop) { (void)shop; /* unused */ }
64
69 virtual void VisitCondimentGrocer(Visitor_CondimentGrocer* shop) { (void)shop; /* unused */ }
70
75 virtual void VisitPickleGrocer(Visitor_PickleGrocer* shop) { (void)shop; /* unused */ }
76
81 virtual void VisitMaker(Visitor_Maker* shop) { (void)shop; /* unused */ }
82 };
83
84
85
86 //-------------------------------------------------------------------------
87 //-------------------------------------------------------------------------
88
89
94 {
99 void Accept(Visitor* visitor)
100 {
101 if (visitor != nullptr)
102 {
103 visitor->VisitRestaurant(this);
104 }
105 }
106 };
107
108
109 //-------------------------------------------------------------------------
110 //-------------------------------------------------------------------------
111
112
117 {
122 void Accept(Visitor* visitor)
123 {
124 if (visitor != nullptr)
125 {
126 visitor->VisitButcher(this);
127 }
128 }
129 };
130
131
132 //-------------------------------------------------------------------------
133 //-------------------------------------------------------------------------
134
135
140 {
145 void Accept(Visitor* visitor)
146 {
147 if (visitor != nullptr)
148 {
149 visitor->VisitBaker(this);
150 }
151 }
152 };
153
154
155 //-------------------------------------------------------------------------
156 //-------------------------------------------------------------------------
157
158
163 {
168 void Accept(Visitor* visitor)
169 {
170 if (visitor != nullptr)
171 {
172 visitor->VisitVegetableGrocer(this);
173 }
174 }
175 };
176
177
178 //-------------------------------------------------------------------------
179 //-------------------------------------------------------------------------
180
181
186 {
191 void Accept(Visitor* visitor)
192 {
193 if (visitor != nullptr)
194 {
195 visitor->VisitCondimentGrocer(this);
196 }
197 }
198 };
199
200
201 //-------------------------------------------------------------------------
202 //-------------------------------------------------------------------------
203
204
209 {
214 void Accept(Visitor* visitor)
215 {
216 if (visitor != nullptr)
217 {
218 visitor->VisitPickleGrocer(this);
219 }
220 }
221 };
222
223
224 //-------------------------------------------------------------------------
225 //-------------------------------------------------------------------------
226
227
232 {
237 void Accept(Visitor* visitor)
238 {
239 if (visitor != nullptr)
240 {
241 visitor->VisitMaker(this);
242 }
243 }
244 };
245
246
247 //-------------------------------------------------------------------------
248 //-------------------------------------------------------------------------
249
250
251
252} // end namespace
253
254#endif // __VISITOR_ELEMENT_CLASSES_H__
void Accept(Visitor *visitor)
Handle visitors to this class.
void Accept(Visitor *visitor)
Handle visitors to this class.
void Accept(Visitor *visitor)
Handle visitors to this class.
void Accept(Visitor *visitor)
Handle visitors to this class.
void Accept(Visitor *visitor)
Handle visitors to this class.
void Accept(Visitor *visitor)
Handle visitors to this class.
Base class that all shops must implement.
void Accept(Visitor *visitor)
Handle visitors to this class.
All visitors must implement this base class and then override one or more of the VisitXXX() methods,...
virtual void VisitMaker(Visitor_Maker *shop)
Let the visitor visit a Visitor_Maker shop.
virtual void VisitVegetableGrocer(Visitor_VegetableGrocer *shop)
Let the visitor visit a Visitor_VegetableGrocer shop.
virtual void VisitCondimentGrocer(Visitor_CondimentGrocer *shop)
Let the visitor visit a Visitor_CondimentGrocer shop.
virtual void VisitButcher(Visitor_Butcher *shop)
Let the visitor visit a Visitor_Butcher shop.
virtual void VisitPickleGrocer(Visitor_PickleGrocer *shop)
Let the visitor visit a Visitor_PickleGrocer shop.
virtual void VisitRestaurant(Visitor_Restaurant *shop)
Let the visitor visit a Visitor_Restaurant shop.
virtual void VisitBaker(Visitor_Baker *shop)
Let the visitor visit a Visitor_Baker shop.
Declaration of the Visitor_Shop base class used in the Visitor Pattern.
The namespace containing all Design Pattern Examples implemented in C++.