-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate.cpp
More file actions
83 lines (71 loc) · 1.86 KB
/
Template.cpp
File metadata and controls
83 lines (71 loc) · 1.86 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
/**
* @cite Template Pattern states that the skeleton of the algorithm should be defined in the base interface and the details of implementation are decided by the inheritors.
* Aims at promoting Code Reusability and Modularity.
*
* @brief Template Pattern can be exemplified by a Device interface that exposes a single run() function which defines the general flow of device and leaves the implementation details to the inheritors.
*/
#include <iostream>
/**
* @brief Defines the general flow of a device.
*/
class Device
{
public:
void run()
{
boot();
load_drivers();
display();
get_input();
}
protected:
virtual void boot() = 0;
virtual void load_drivers() = 0;
virtual void display() = 0;
virtual void get_input() = 0;
};
/**
* @brief Implements Device with Android related functionalities.
*/
class AndroidDevice : public Device
{
void boot() override {
std::cout << "Booting up the Android Device....\n";
}
void load_drivers() override {
std::cout << "Loading Drivers for Android hardware...\n";
}
void display() override {
std::cout << "Display is turned on ...\n";
}
void get_input() override {
std::cout << "Waiting for input....\n";
}
};
/**
* @brief Implements Device with Windows related functionalities.
*/
class WindowsDevice : public Device
{
void boot() override {
std::cout << "Booting up the Windows Device....\n";
}
void load_drivers() override {
std::cout << "Loading Drivers for Windows hardware...\n";
}
void display() override {
std::cout << "Display is turned on ...\n";
}
void get_input() override {
std::cout << "Waiting for input....\n";
}
};
int main()
{
AndroidDevice ad;
ad.run();
std::cout << "\n";
WindowsDevice wd;
wd.run();
return 0;
}