File tree Expand file tree Collapse file tree 2 files changed +90
-1
lines changed Expand file tree Collapse file tree 2 files changed +90
-1
lines changed Original file line number Diff line number Diff line change @@ -22,4 +22,5 @@ set(CMAKE_CXX_STANDARD 20)
22
22
#add_executable(lspqueryset LSP/lsp_query_set.cpp)
23
23
#add_executable(isp_door ISP/isp_door_example.cpp)
24
24
#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 )
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments