|
2 | 2 |
|
3 | 3 | # Bad example |
4 | 4 | # class Printer(ABC): |
5 | | -# """Printer interface.""" |
6 | | - |
7 | 5 | # @abstractmethod |
8 | 6 | # def print(self, document): |
9 | 7 | # pass |
|
18 | 16 |
|
19 | 17 |
|
20 | 18 | # class OldPrinter(Printer): |
21 | | -# """Old printer, concrete implementation.""" |
22 | | - |
23 | 19 | # def print(self, document): |
24 | | -# print(f"Print {document} in black and white") |
| 20 | +# print(f"Printing {document} in black and white...") |
25 | 21 |
|
26 | 22 | # def fax(self, document): |
27 | 23 | # raise NotImplementedError("Fax functionality not supported") |
|
31 | 27 |
|
32 | 28 |
|
33 | 29 | # class ModernPrinter(Printer): |
34 | | -# """Modern printer, concrete implementation.""" |
35 | | - |
36 | 30 | # def print(self, document): |
37 | | -# print(f"Printing {document} in color") |
| 31 | +# print(f"Printing {document} in color...") |
38 | 32 |
|
39 | 33 | # def fax(self, document): |
40 | | -# print(f"Faxing {document}") |
| 34 | +# print(f"Faxing {document}...") |
41 | 35 |
|
42 | 36 | # def scan(self, document): |
43 | | -# print(f"Scanning {document}") |
| 37 | +# print(f"Scanning {document}...") |
44 | 38 |
|
45 | 39 |
|
46 | 40 | # Good example |
47 | 41 | class Printer(ABC): |
48 | | - """Printer interface.""" |
49 | | - |
50 | 42 | @abstractmethod |
51 | 43 | def print(self, document): |
52 | 44 | pass |
53 | 45 |
|
54 | 46 |
|
55 | 47 | class Fax(ABC): |
56 | | - """Fax interface.""" |
57 | | - |
58 | 48 | @abstractmethod |
59 | 49 | def fax(self, document): |
60 | 50 | pass |
61 | 51 |
|
62 | 52 |
|
63 | | -class Scan(ABC): |
64 | | - """Scan interface.""" |
65 | | - |
| 53 | +class Scanner(ABC): |
66 | 54 | @abstractmethod |
67 | 55 | def scan(self, document): |
68 | 56 | pass |
69 | 57 |
|
70 | 58 |
|
71 | 59 | class OldPrinter(Printer): |
72 | | - """Old printer, concrete implementation.""" |
73 | | - |
74 | 60 | def print(self, document): |
75 | | - print(f"Print {document} in black and white") |
76 | | - |
| 61 | + print(f"Printing {document} in black and white...") |
77 | 62 |
|
78 | | -class NewPrinter(Printer, Fax, Scan): |
79 | | - """New printer, concrete implementation.""" |
80 | 63 |
|
| 64 | +class NewPrinter(Printer, Fax, Scanner): |
81 | 65 | def print(self, document): |
82 | | - print(f"Printing {document} in color") |
| 66 | + print(f"Printing {document} in color...") |
83 | 67 |
|
84 | 68 | def fax(self, document): |
85 | | - print(f"Faxing {document}") |
| 69 | + print(f"Faxing {document}...") |
86 | 70 |
|
87 | 71 | def scan(self, document): |
88 | | - print(f"Scanning {document}") |
89 | | - print(f"Scanning {document}") |
| 72 | + print(f"Scanning {document}...") |
0 commit comments