-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_method.py
49 lines (36 loc) · 1.16 KB
/
template_method.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
# --------------------------------------------------------
# Licensed under the terms of the BSD 3-Clause License
# (see LICENSE for details).
# Copyright © 2018-2024, A.A Suvorov
# All rights reserved.
# --------------------------------------------------------
# https://github.com/smartlegionlab/
# --------------------------------------------------------
"""Template Method"""
class ExampleBase:
def template_method(self):
self.step_one()
self.step_two()
self.step_three()
def step_one(self):
raise NotImplementedError()
def step_two(self):
raise NotImplementedError()
def step_three(self):
raise NotImplementedError()
class Example(ExampleBase):
def step_one(self):
print('The first step of the algorithm')
def step_two(self):
print('The second step of the algorithm')
def step_three(self):
print('The third step of the algorithm')
def main():
example = Example()
example.template_method()
if __name__ == '__main__':
# Output:
# The first step of the algorithm
# The second step of the algorithm
# The third step of the algorithm
main()