-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_method.py
55 lines (37 loc) · 1.02 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
50
51
52
53
54
55
from abc import ABC, abstractmethod
class Top(ABC):
def template_method(self):
self.first_common()
self.second_common()
self.third_require()
self.fourth_require()
self.hook()
def first_common(self):
print('I am first common...')
def second_common(self):
print('I am second common...')
@abstractmethod
def third_require(self):
pass
@abstractmethod
def fourth_require(self):
pass
def hook(self):
pass
class One(Top):
def third_require(self):
print('I am third require from One...')
def fourth_require(self):
print('I am fourth require from One...')
def hook(self):
print('I am Hook from One...')
class Two(Top):
def third_require(self):
print('I am third require from Two...')
def fourth_require(self):
print('I am fourth require from Two...')
def client(class_):
class_().template_method()
if __name__ == '__main__':
client(One)
client(Two)