-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
77 lines (62 loc) · 2.2 KB
/
main.cpp
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
#include <iostream>
#include <memory>
#include "container_receiver.hpp"
#include "create_command.hpp"
#include "delete_command.hpp"
#include "element.hpp"
#include "invoker.hpp"
#include "read_command.hpp"
#include "single_receiver.hpp"
#include "update_command.hpp"
int main() {
const auto firstId = "first";
const auto secondId = "second";
const auto thirdId = "third";
std::cout << "Create elements\n";
Element firstElement{firstId};
Element secondElement{secondId};
std::cout << "Create receivers\n";
auto firstReceiver = std::make_shared<SingleReceiver>();
auto secondReceiver = std::make_shared<ContainerReceiver>();
{
std::cout << "SingleReceiver start\n";
auto firstCommand = std::make_shared<CreateCommand>(firstReceiver, firstId);
auto secondCommand =
std::make_shared<CreateCommand>(firstReceiver, thirdId);
auto thirdCommand = std::make_shared<ReadCommand>(firstReceiver);
auto fourthCommand =
std::make_shared<UpdateCommand>(firstReceiver, secondElement);
auto fifthCommand =
std::make_shared<DeleteCommand>(firstReceiver, secondElement);
Invoker invoker;
invoker.addCommand(firstCommand);
invoker.addCommand(secondCommand);
invoker.addCommand(thirdCommand);
invoker.addCommand(fourthCommand);
invoker.addCommand(fifthCommand);
invoker.executeCommands();
std::cout << "SingleReceiver end\n";
}
{
std::cout << "ContainerReceiver start\n";
auto firstCommand =
std::make_shared<CreateCommand>(secondReceiver, firstId);
auto secondCommand =
std::make_shared<CreateCommand>(secondReceiver, thirdId);
auto thirdCommand = std::make_shared<ReadCommand>(secondReceiver);
auto fourthCommand =
std::make_shared<UpdateCommand>(secondReceiver, secondElement);
auto fifthCommand =
std::make_shared<DeleteCommand>(secondReceiver, secondElement);
Invoker invoker;
invoker.addCommand(firstCommand);
invoker.addCommand(secondCommand);
invoker.addCommand(thirdCommand);
invoker.addCommand(fourthCommand);
invoker.addCommand(fifthCommand);
invoker.executeCommands();
std::cout << "ContainerReceiver end\n";
}
std::cout << "Done\n";
return 0;
}