-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patho_good.py
More file actions
30 lines (24 loc) · 703 Bytes
/
Copy patho_good.py
File metadata and controls
30 lines (24 loc) · 703 Bytes
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
from abc import ABC, abstractmethod
# Abstract base class for outputs.
class Output(ABC):
def __init__(self, data):
self.data = data
# Declare an abstract display method.
@abstractmethod
def display(self):
pass
# Console output implementation.
class ConsoleOutput(Output):
def display(self):
print(f"{self.data}")
# File output implementation.
class FileOutput(Output):
def display(self):
with open('output.txt', 'w') as f:
f.write(self.data)
# Create a ConsoleOutput object and display.
obj = ConsoleOutput("some string")
obj.display()
# Create a FileOutput object and display.
obj2 = FileOutput("another string")
obj2.display()