1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ class MisDepartment
6
+ {
7
+ public:
8
+ void submitNetworkRequest ()
9
+ {
10
+ _state = 0 ;
11
+ }
12
+ bool checkOnStatus ()
13
+ {
14
+ _state++;
15
+ if (_state == Complete)
16
+ return 1 ;
17
+ return 0 ;
18
+ }
19
+
20
+ private:
21
+ enum States
22
+ {
23
+ Received,
24
+ DenyAllKnowledge,
25
+ ReferClientToFacilities,
26
+ FacilitiesHasNotSentPaperwork,
27
+ ElectricianIsNotDone,
28
+ ElectricianDidItWrong,
29
+ DispatchTechnician,
30
+ SignedOff,
31
+ DoesNotWork,
32
+ FixElectriciansWiring,
33
+ Complete
34
+ };
35
+ int _state;
36
+ };
37
+
38
+ class ElectricianUnion
39
+ {
40
+ public:
41
+ void submitNetworkRequest ()
42
+ {
43
+ _state = 0 ;
44
+ }
45
+ bool checkOnStatus ()
46
+ {
47
+ _state++;
48
+ if (_state == Complete)
49
+ return 1 ;
50
+ return 0 ;
51
+ }
52
+
53
+ private:
54
+ enum States
55
+ {
56
+ Received,
57
+ RejectTheForm,
58
+ SizeTheJob,
59
+ SmokeAndJokeBreak,
60
+ WaitForAuthorization,
61
+ DoTheWrongJob,
62
+ BlameTheEngineer,
63
+ WaitToPunchOut,
64
+ DoHalfAJob,
65
+ ComplainToEngineer,
66
+ GetClarification,
67
+ CompleteTheJob,
68
+ TurnInThePaperwork,
69
+ Complete
70
+ };
71
+ int _state;
72
+ };
73
+
74
+ class FacilitiesDepartment
75
+ {
76
+ public:
77
+ void submitNetworkRequest ()
78
+ {
79
+ _state = 0 ;
80
+ }
81
+ bool checkOnStatus ()
82
+ {
83
+ _state++;
84
+ if (_state == Complete)
85
+ return 1 ;
86
+ return 0 ;
87
+ }
88
+
89
+ private:
90
+ enum States
91
+ {
92
+ Received,
93
+ AssignToEngineer,
94
+ EngineerResearches,
95
+ RequestIsNotPossible,
96
+ EngineerLeavesCompany,
97
+ AssignToNewEngineer,
98
+ NewEngineerResearches,
99
+ ReassignEngineer,
100
+ EngineerReturns,
101
+ EngineerResearchesAgain,
102
+ EngineerFillsOutPaperWork,
103
+ Complete
104
+ };
105
+ int _state;
106
+ };
107
+
108
+ class FacilitiesFacade
109
+ {
110
+ public:
111
+ FacilitiesFacade ()
112
+ {
113
+ _count = 0 ;
114
+ }
115
+ void submitNetworkRequest ()
116
+ {
117
+ _state = 0 ;
118
+ }
119
+ bool checkOnStatus ()
120
+ {
121
+ _count++;
122
+ /* Job request has just been received */
123
+ if (_state == Received)
124
+ {
125
+ _state++;
126
+ /* Forward the job request to the engineer */
127
+ _engineer.submitNetworkRequest ();
128
+ cout << " submitted to Facilities - " << _count << " phone calls so far" << endl;
129
+ }
130
+ else if (_state == SubmitToEngineer)
131
+ {
132
+ /* If engineer is complete, forward to electrician */
133
+ if (_engineer.checkOnStatus ())
134
+ {
135
+ _state++;
136
+ _electrician.submitNetworkRequest ();
137
+ cout << " submitted to Electrician - " << _count << " phone calls so far" << endl;
138
+ }
139
+ }
140
+ else if (_state == SubmitToElectrician)
141
+ {
142
+ /* If electrician is complete, forward to technician */
143
+ if (_electrician.checkOnStatus ())
144
+ {
145
+ _state++;
146
+ _technician.submitNetworkRequest ();
147
+ cout << " submitted to MIS - " << _count << " phone calls so far" << endl;
148
+ }
149
+ }
150
+ else if (_state == SubmitToTechnician)
151
+ {
152
+ /* If technician is complete, job is done */
153
+ if (_technician.checkOnStatus ())
154
+ return 1 ;
155
+ }
156
+ /* The job is not entirely complete */
157
+ return 0 ;
158
+ }
159
+ int getNumberOfCalls ()
160
+
161
+ {
162
+ return _count;
163
+ }
164
+
165
+ private:
166
+ enum States
167
+ {
168
+ Received,
169
+ SubmitToEngineer,
170
+ SubmitToElectrician,
171
+ SubmitToTechnician
172
+ };
173
+ int _state;
174
+ int _count;
175
+ FacilitiesDepartment _engineer;
176
+ ElectricianUnion _electrician;
177
+ MisDepartment _technician;
178
+ };
179
+
180
+ int main ()
181
+ {
182
+ FacilitiesFacade facilities;
183
+
184
+ facilities.submitNetworkRequest ();
185
+ /* Keep checking until job is complete */
186
+ while (!facilities.checkOnStatus ())
187
+ ;
188
+ cout << " job completed after only " << facilities.getNumberOfCalls () << " phone calls" << endl;
189
+ }
0 commit comments