-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path16_template method.py
50 lines (35 loc) · 973 Bytes
/
16_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
"""
Template Method
- a behavioral design pattern that defines the skeleton of an algorithm in the superclass
but lets subclasses override specific steps of the algorithm without changing its structure.
"""
import abc
class Top(abc.ABC):
def template_method(self):
self.first_common()
self.second_common()
self.third_require()
self.fourth_require()
def first_common(self):
print('This is first common...')
def second_common(self):
print('This is second common...')
@abc.abstractmethod
def third_require(self):
pass
@abc.abstractmethod
def fourth_require(self):
pass
class One(Top):
def third_require(self):
print('This is third require from One')
def fourth_require(self):
print('This is fourth require from One')
class Two(Top):
def third_require(self):
print('This is third require from Two')
def fourth_require(self):
print('This is fourth require from Two')
def client(klass):
klass.template_method()
client(Two())