-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
405 lines (265 loc) · 10.6 KB
/
main.cpp
File metadata and controls
405 lines (265 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// #include "CreationalDesignPatterns/Builder/builder.hpp"
// int main(){
// int temp = 0;
// Office center_office = Office::Builder("R&D Center Office")
// .cooler_builder()
// .set_cooler_type(100)
// .hw_builder()
// .set_computer_brand(101).get_office();
// center_office.display_office_properties();
// OfficeBaseBuilder o_builder = Office::Builder("Production Plant");
// Office production_office = o_builder.cooler_builder()
// .set_cooler_type(10)
// .hw_builder()
// .set_computer_brand(11);
// production_office.display_office_properties();
// return 0;
// }
// #include "CreationalDesignPatterns/Factories/factories.hpp"
// int main() {
// {
// std::unique_ptr<OfficeFactory> factory_sw_department = std::make_unique<RDCenterOfficeFactory>();
// auto cooler = factory_sw_department->createCooler();
// auto computers = factory_sw_department->createComputer();
// cooler->cool();
// computers->compute();
// }
// {
// std::unique_ptr<ProductionFactoryFactory> production_plant = std::make_unique<ProductionFactoryFactory>();
// auto cooler = production_plant->createCooler();
// auto computers = production_plant->createComputer();
// cooler->cool();
// computers->compute();
// }
// }
// #include "CreationalDesignPatterns/Prototype/prototype.hpp"
// int main() {
// // Creating a base prototype
// std::unique_ptr<Office> center_office = std::make_unique<CenterRDOffice>(6000,8086,"R&D Center", "Ankara", "Tunali Hilmi", "It happens when you work.");
// center_office->display_office_properties();
// std::unique_ptr<Office> second_office = center_office->clone();
// dynamic_cast<CenterRDOffice*>(second_office.get())->set_office_name("R&D Center (Additional Service Building)"); // Adjust address for the new office
// dynamic_cast<CenterRDOffice*>(second_office.get())->set_address("Ardahan", "Cumhuriyet"); // Adjust address for the new office
// dynamic_cast<CenterRDOffice*>(second_office.get())->set_motto("get up! stand up! dont give up the fight."); // Adjust address for the new office
// second_office->display_office_properties();
// }
// #include "CreationalDesignPatterns/Singleton/singleton.hpp"
// int main() {
// SingletonOfficeDatabase::get_reference().display_database();
// return 0;
// }
// #include "CreationalDesignPatterns/Adapter/adapter.hpp"
// int main()
// {
// std::cout << "Legacy Cooler: \n";
// LegacyCooler legacy_cooler;
// client_cooler_app(legacy_cooler);
// std::cout << "--------------------------\n";
// std::cout << "New cooler is set up.\n";
// CoolerAdapter adapted_legacy_cooler;
// client_cooler_app(adapted_legacy_cooler);
// return 0;
// }
// #include "CreationalDesignPatterns/Bridge/bridge.hpp"
// int main()
// {
// AnimationBasedRenderer anim_render{};
// Book book{anim_render, 150, 2};
// book.create_images();
// Pen pen(anim_render, 41, 67);
// pen.create_images();
// AIBasedRenderer ai_render{};
// Pen pen_2{ai_render, 06, 75};
// pen_2.create_images();
// return 0;
// }
// #include "CreationalDesignPatterns/Composite/composite.hpp"
// #include <iostream>
// int company_total_production(const std::vector<TotalProduction*> items)
// {
// int result{0};
// for (auto item : items)
// {
// result += item->get_production(); // it is same interface for single office or multiple offices.
// }
// return result;
// }
// int main()
// {
// SingleOffice s(10);
// ProductionPlant p;
// p.add_production(20);
// p.add_production(30);
// std::vector<TotalProduction*> offices;
// offices.push_back(&s);
// offices.push_back(&p);
// // int total = company_total_production({ &s, &p }); /* this also works, alternative way to pass arguments*/
// int total = company_total_production(offices);
// std::cout << "Total Production: " << total << std::endl;
// return 0;
// }
// #include "CreationalDesignPatterns/Flyweight/flyweight.hpp"
// int main()
// {
// EmployeeFamilyMember yilmaz{ "Yilmaz", "Gibi" };
// EmployeeFamilyMember ilkkan{ "Ilkkan", "Gibi" };
// cout << "Yilmaz -> " << yilmaz << endl;
// cout << "Ilkkan -> " << ilkkan << endl;
// EmployeeFamilyMember::info();
// return 0;
// }
// #include "CreationalDesignPatterns/Proxy/proxy.hpp"
// int main() {
// Catalog * product_promotion_material = new ProxyCatalog("NewPromotion.png");
// product_promotion_material->display();
// product_promotion_material->display();
// }
// #include "BehavioralDesignPatterns/ChainOfResponsibility/chainOfResponsibility.hpp"
// int main()
// {
// Employee ersoy{"Ersoy", 3, 50000};
// ersoy.display();
// EmployeePromoter root{ersoy};
// HumanResourcesPromoter hr_promoter{ersoy};
// AccountPromoter acc_promoter{ersoy};
// DirectorPromoter dir_promoter{ersoy};
// root.add_promoter(&hr_promoter);
// root.add_promoter(&acc_promoter);
// root.add_promoter(&dir_promoter);
// root.add_promoter(&acc_promoter); // this is not called anoymore since Director is the last promoter
// // determined in DirectorPromoter class itself.
// root.handle();
// ersoy.display();
// return 0;
// }
// #include "BehavioralDesignPatterns/Command/command.hpp"
// int main()
// {
// // BankAccount ba;
// // CompositeBankAccountCommand commands{
// // BankAccountCommand{ ba, BankAccountCommand::deposit, 100 },
// // BankAccountCommand{ ba, BankAccountCommand::withdraw, 200 }
// // };
// // cout << ba.balance << endl;
// // commands.call();
// // cout << ba.balance << endl;
// // commands.undo();
// // cout << ba.balance << endl;
// BankAccount sender, receiver;
// MoneyTransferCommand transfer(receiver, sender, 300);
// transfer.call();
// cout << "sender balance : " << sender.balance << endl;
// cout << "receiver balance :" << receiver.balance << endl;
// transfer.undo();
// cout << "sender balance : " << sender.balance << endl;
// cout << "receiver balance :" << receiver.balance << endl;
// cout << "--------------------------------------------" << endl;
// cout << "INVALID TRANSFER::" << endl;
// MoneyTransferCommand transfer_invalid(receiver, sender, 3000);
// transfer_invalid.call();
// cout << "sender balance : " << sender.balance << endl;
// cout << "receiver balance :" << receiver.balance << endl;
// transfer_invalid.undo();
// cout << "sender balance : " << sender.balance << endl;
// cout << "receiver balance :" << receiver.balance << endl;
// return 0;
// }
// #include "BehavioralDesignPatterns/Iterator/iterator.hpp"
// int main()
// {
// iterators_in_stl();
// iterator_in_boost();
// return 0;
// }
// #include "BehavioralDesignPatterns/Mediator/mediator.hpp"
// int main()
// {
// ChatRoom room;
// Person john{"John"};
// Person jane{"Jane"};
// room.join(&john);
// room.join(&jane);
// john.say("hi room");
// jane.say("oh, hey john");
// Person simon{"Simon"};
// room.join(&simon);
// simon.say("hi everyone!");
// jane.pm("Simon", "glad you found us, simon!");
// return 0;
// }
// #include "BehavioralDesignPatterns/Memento/memento.hpp"
// int main()
// {
// BankAccount bank_account{ 200 };
// bank_account.deposit(100);
// bank_account.deposit(50);
// cout << bank_account << "\n"; // should expect 350
// /*
// Timeline --> (current)
// ^
// [deposit-100 deposit-50 ]
// */
// // undo is applied current, and move current to previous one
// bank_account.undo();
// cout << "Undo 1: " << bank_account << "\n"; // undo depoziting 50, should be 300
// /*
// New Timeline --> (current)
// ^
// [deposit-100 deposit-50 ]
// */
// bank_account.undo();
// cout << "Undo 2: " << bank_account << "\n"; // again undo depoziting 100, should be 200
// bank_account.redo();
// cout << "Redo 2: " << bank_account << "\n"; // redo depoziting 100, should be again 300
// bank_account.undo();
// cout << "Undo 3: " << bank_account << "\n"; // undo depoziting 100 again, should be again 200
// return 0;
// }
// #include "BehavioralDesignPatterns/Observer/observer.hpp"
// int main()
// {
// Employee e{20, 1100};
// HRAnnualObserver hr_salary_observer;
// e.subscribe(hr_salary_observer);
// HRBirthdayObserver hr_anniversary_observer;
// e.subscribe(hr_anniversary_observer);
// e.birthday(); // 21
// e.anniversary();
// e.unsubscribe(hr_salary_observer);
// e.anniversary(); // do not care since this is unsubscribed
// e.birthday();
// e.birthday();
// e.birthday();
// e.birthday(); // age 25, last annual leave gift is given.
// // then unsubscribe annual leave topic and
// // no further notify is updated
// e.birthday();
// e.birthday();
// e.birthday();
// e.birthday();
// return 0;
// }
// #include "BehavioralDesignPatterns/Strategy/strategy.hpp"
// int main()
// {
// vector<string> msgs{"yilmaz", "ilkkan", "ersoy"};
// TextProcessor text_processor;
// text_processor.set_output_format(OutputFormat::Markdown);
// text_processor.append_list(msgs);
// cout << text_processor.str() << endl;
// text_processor.clear();
// // now switch different format
// text_processor.set_output_format(OutputFormat::Html);
// text_processor.append_list(msgs);
// cout << text_processor.str() << endl;
// text_processor.clear();
// StaticTextProcessor<HtmloutputFormatStrategies> static_html_text_processor;
// vector<string> msgs_static{"aragorn", "legolas", "gimli"};
// static_html_text_processor.append_list(msgs_static);
// cout << static_html_text_processor.str() << endl;
// StaticTextProcessor<MarkdownoutputFormatStrategies> static_md_text_processor;
// vector<string> msgs_static2{"frodo", "samwise", "pipping", "merry"};
// static_md_text_processor.append_list(msgs_static2);
// cout << static_md_text_processor.str() << endl;
// return 0;
// }