-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.py
74 lines (56 loc) · 1.51 KB
/
template.py
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
from abc import ABC, abstractmethod
# Abstract Class
class DataProcessor(ABC):
def process_data(self): # templateMethod()
self.read_data()
self.parse_data()
self.analyze_data()
self.display_results()
@abstractmethod
def read_data(self):
pass
@abstractmethod
def parse_data(self):
pass
@abstractmethod
def analyze_data(self):
pass
def display_results(self):
print("Displaying results...")
# Concrete Class1
class XMLDataProcessor(DataProcessor):
def read_data(self):
print("Reading data from XML file...")
def parse_data(self):
print("Parsing XML data...")
def analyze_data(self):
print("Analyzing XML data...")
# Concrete Class2
class CSVDataProcessor(DataProcessor):
def read_data(self):
print("Reading data from CSV file...")
def parse_data(self):
print("Parsing CSV data...")
def analyze_data(self):
print("Analyzing CSV data...")
# Client code
def client_code():
xml_processor = XMLDataProcessor()
csv_processor = CSVDataProcessor()
print("Processing XML data:")
xml_processor.process_data()
print("\nProcessing CSV data:")
csv_processor.process_data()
# Usage
client_code()
## Output
# Processing XML data:
# Reading data from XML file...
# Parsing XML data...
# Analyzing XML data...
# Displaying results...
# Processing CSV data:
# Reading data from CSV file...
# Parsing CSV data...
# Analyzing CSV data...
# Displaying results...