Design Pattern Examples
Overview of object-oriented design patterns
Visitor_Visitor_Class.h
Go to the documentation of this file.
1
5
6#pragma once
7#ifndef __VISITOR_VISITOR_CLASS_H__
8#define __VISITOR_VISITOR_CLASS_H__
9
10#include "helpers/stringlist.h"
11
13
15{
16
24 class OrderVisitor : public Visitor
25 {
26 protected:
31
32 public:
37
42
48 : ItemsToOrder(itemsToOrder)
49 {
50 }
51
52 void VisitBaker(Visitor_Baker* shop) override
53 {
54 if (shop != nullptr)
55 {
56 if (shop->PlaceOrder(ItemsToOrder))
57 {
59 ShopNameReceivedFrom = shop->Name();
60 }
61 }
62 }
63
64 void VisitButcher(Visitor_Butcher* shop) override
65 {
66 if (shop != nullptr)
67 {
68 if (shop->PlaceOrder(ItemsToOrder))
69 {
71 ShopNameReceivedFrom = shop->Name();
72 }
73 }
74 }
75
77 {
78 if (shop != nullptr)
79 {
80 if (shop->PlaceOrder(ItemsToOrder))
81 {
83 ShopNameReceivedFrom = shop->Name();
84 }
85 }
86 }
87
89 {
90 if (shop != nullptr)
91 {
92 if (shop->PlaceOrder(ItemsToOrder))
93 {
95 ShopNameReceivedFrom = shop->Name();
96 }
97 }
98 }
99
101 {
102 if (shop != nullptr)
103 {
104 if (shop->PlaceOrder(ItemsToOrder))
105 {
107 ShopNameReceivedFrom = shop->Name();
108 }
109 }
110 }
111
112 void VisitMaker(Visitor_Maker* shop) override
113 {
114 if (shop != nullptr)
115 {
116 if (shop->PlaceOrder(ItemsToOrder))
117 {
119 ShopNameReceivedFrom = shop->Name();
120 }
121 }
122 }
123
125 {
126 if (shop != nullptr)
127 {
128 if (shop->PlaceOrder(ItemsToOrder))
129 {
131 ShopNameReceivedFrom = shop->Name();
132 }
133 }
134 }
135 };
136
137} // end namespace
138
139#endif // __VISITOR_VISITOR_CLASS_H__
Declaration of the Visitor base class and the various shop classes used in the Visitor Pattern.
A visitor used for ordering items from various shops. The user starts with an instance of this class ...
StringList ItemsReceived
List of items received from an order/pickup process.
void VisitVegetableGrocer(Visitor_VegetableGrocer *shop) override
Let the visitor visit a Visitor_VegetableGrocer shop.
void VisitCondimentGrocer(Visitor_CondimentGrocer *shop) override
Let the visitor visit a Visitor_CondimentGrocer shop.
StringList ItemsToOrder
Items to be ordered from any shop that sells the item.
void VisitPickleGrocer(Visitor_PickleGrocer *shop) override
Let the visitor visit a Visitor_PickleGrocer shop.
void VisitRestaurant(Visitor_Restaurant *shop) override
Let the visitor visit a Visitor_Restaurant shop.
std::string ShopNameReceivedFrom
Name of the shop that provided the item(s).
void VisitButcher(Visitor_Butcher *shop) override
Let the visitor visit a Visitor_Butcher shop.
OrderVisitor(StringList itemsToOrder)
Constructor.
void VisitBaker(Visitor_Baker *shop) override
Let the visitor visit a Visitor_Baker shop.
void VisitMaker(Visitor_Maker *shop) override
Let the visitor visit a Visitor_Maker shop.
void PickupOrder(StringList items, StringList &itemsToBePickedUp)
Pick up the items sold by this shop (assumes the items were ordered already). Basically,...
bool PlaceOrder(StringList items)
Place an order for the specified items. If the inventory is empty, replenish the inventory by visitin...
All visitors must implement this base class and then override one or more of the VisitXXX() methods,...
std::vector< std::string > StringList
Typedef for a vector of std::string.
The namespace containing all Design Pattern Examples implemented in C++.