Skip to content

Commit ff7c68f

Browse files
author
sajith
committed
Improved
1 parent d3c6ad6 commit ff7c68f

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ set(CMAKE_CXX_STANDARD 20)
2222
#add_executable(lspqueryset LSP/lsp_query_set.cpp)
2323
#add_executable(isp_door ISP/isp_door_example.cpp)
2424
#add_executable(isp_door_better ISP/isp_door_example_better.cpp)
25-
add_executable(isp_door_better2 ISP/isp_door_example_better2.cpp)
25+
#add_executable(isp_door_better2 ISP/isp_door_example_better2.cpp)
26+
add_executable(isp_device ISP/isp_device_example.cpp)

ISP/isp_device_example.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// Created by sajith on 4/19/21.
3+
//
4+
5+
#include <iostream>
6+
#include <stdexcept>
7+
8+
class Device
9+
{
10+
public:
11+
virtual ~Device() = default;
12+
virtual void print() = 0;
13+
virtual void scan() = 0;
14+
virtual void fax() = 0;
15+
};
16+
17+
18+
class AdvancedPrinter : public Device
19+
{
20+
21+
public:
22+
23+
void print()
24+
{
25+
std::cout << "Printing...\n";
26+
}
27+
28+
void scan()
29+
{
30+
std::cout << "Scanning...\n";
31+
}
32+
33+
void fax()
34+
{
35+
std::cout << "Faxing...\n";
36+
}
37+
};
38+
39+
40+
class SimplePrinter : public Device
41+
{
42+
43+
public:
44+
45+
void print()
46+
{
47+
std::cout << "Printing...\n";
48+
}
49+
50+
void scan()
51+
{
52+
throw std::runtime_error{"Not implemented"};
53+
}
54+
55+
void fax()
56+
{
57+
throw std::runtime_error{"Not implemented"};
58+
}
59+
};
60+
61+
// clients
62+
void printUsers(Device &device)
63+
{
64+
device.print();
65+
}
66+
67+
void scanUsers(Device &device)
68+
{
69+
device.scan();
70+
}
71+
72+
void faxUsers(Device &device)
73+
{
74+
device.fax();
75+
}
76+
77+
int main()
78+
{
79+
AdvancedPrinter advancedPrinter;
80+
SimplePrinter simplePrinter;
81+
82+
printUsers(advancedPrinter);
83+
scanUsers(advancedPrinter);
84+
faxUsers(advancedPrinter);
85+
86+
scanUsers(simplePrinter);
87+
return 0;
88+
}

0 commit comments

Comments
 (0)