-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtemplate_method.py
More file actions
81 lines (60 loc) · 1.82 KB
/
template_method.py
File metadata and controls
81 lines (60 loc) · 1.82 KB
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
75
76
77
78
79
80
81
'''
Template method Pattern - This is behavioral design pattern.
'''
import abc
class ThreeDaysTrip(metaclass=abc.ABCMeta):
@abc.abstractmethod
def transport(self):
pass
@abc.abstractmethod
def day1(self):
pass
@abc.abstractmethod
def day2(self):
pass
@abc.abstractmethod
def day3(self):
pass
@abc.abstractmethod
def back_to_home(self):
pass
def iternary(self):
print("Trip is started")
self.transport()
self.day1()
self.day2()
self.day3()
self.back_to_home()
print("Trip is over")
class SouthTrip(ThreeDaysTrip):
def transport(self):
print("Go by train! check in to hotel")
def day1(self):
print("Day-1: Enjoy the hotel beach whole day")
def day2(self):
print("Day-2: Visit historical places and Enjoy cruise life at night")
def day3(self):
print("Day-3: Enjoy shopping day with family and go anywhere you wish")
def back_to_home(self):
print("Check out and go Home by air!")
class NorthTrip(ThreeDaysTrip):
def transport(self):
print("Go by air! check in to hotel")
def day1(self):
print("Day-1: Go to very highted place and enjoy snow activities")
def day2(self):
print("Day-2: Enjoy river rafting and lavish dinner at night")
def day3(self):
print("Day-3: Enjoy shopping day with family and go anywhere you wish")
def back_to_home(self):
print("Check out and go Home by air!")
if __name__ == "__main__":
place = input("Where do you want to go? ")
if place == 'north':
trip = NorthTrip()
trip.iternary()
elif place == 'south':
trip = SouthTrip()
trip.iternary()
else:
print("Sorry, We do not have any trip towards that place!")