-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.外观模式.py
67 lines (55 loc) · 1.4 KB
/
12.外观模式.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
#!/usr/bin/python
#coding:utf8
'''
Decorator
'''
import time
SLEEP = 0.5
# Complex Parts
class 打雷:
def run(self):
print("###### In 打雷 ######")
time.sleep(SLEEP)
print("Setting up")
time.sleep(SLEEP)
print("Running test")
time.sleep(SLEEP)
print("Tearing down")
time.sleep(SLEEP)
print("Test Finished\n")
class 下雨:
def run(self):
print("###### In 下雨 ######")
time.sleep(SLEEP)
print("Setting up")
time.sleep(SLEEP)
print("Running test")
time.sleep(SLEEP)
print("Tearing down")
time.sleep(SLEEP)
print("Test Finished\n")
class 刮风:
def run(self):
print("###### In 刮风 ######")
time.sleep(SLEEP)
print("Setting up")
time.sleep(SLEEP)
print("Running test")
time.sleep(SLEEP)
print("Tearing down")
time.sleep(SLEEP)
print("Test Finished\n")
# Facade
class 雨天:
def __init__(self):
self.tc1 = 打雷()
self.tc2 = 下雨()
self.tc3 = 刮风()
self.tests = [i for i in (self.tc1, self.tc2, self.tc3)]
def 现象(self):
[i.run() for i in self.tests]
# Client
#加入以后阴天现象里又增加了洪水、泥石流 ,我们的调用接口不变
if __name__ == '__main__':
testrunner = 雨天()
testrunner.现象()