-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacade.py
111 lines (87 loc) · 2.62 KB
/
Facade.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python
# -*- coding : utf-8 -*-
"""
The Facade design pattern is one of the twenty-three well-known GoF design patterns that describe
how to solve recurring design problems to design flexible and reusable object-oriented software,
that is, objects that are easier to implement, change, test, and reuse.
*What problems can the Facade design pattern solve?
- To make a complex subsystem easier to use, a simple interface should be provided for a set of
interfaces in the subsystem.
- The dependencies on a subsystem should be minimized.
Clients that access a complex subsystem directly refer to (depend on) many different objects having
different interfaces (tight coupling), which makes the clients hard to implement, change, test, and reuse.
*What solution does the Facade design pattern describe?
Define a Facade object that
- implements a simple interface in terms of (by delegating to) the interfaces in the subsystem and
- may perform additional functionality before/after forwarding a request.
Reference: https://en.wikipedia.org/wiki/Facade_pattern
"""
from __future__ import print_function
import time
SLEEP = 0.1
# Complex Parts
class TC1:
def run(self):
print(u"###### In Test 1 ######")
time.sleep(SLEEP)
print(u"Setting up")
time.sleep(SLEEP)
print(u"Running test")
time.sleep(SLEEP)
print(u"Tearing down")
time.sleep(SLEEP)
print(u"Test Finished\n")
class TC2:
def run(self):
print(u"###### In Test 2 ######")
time.sleep(SLEEP)
print(u"Setting up")
time.sleep(SLEEP)
print(u"Running test")
time.sleep(SLEEP)
print(u"Tearing down")
time.sleep(SLEEP)
print(u"Test Finished\n")
class TC3:
def run(self):
print(u"###### In Test 3 ######")
time.sleep(SLEEP)
print(u"Setting up")
time.sleep(SLEEP)
print(u"Running test")
time.sleep(SLEEP)
print(u"Tearing down")
time.sleep(SLEEP)
print(u"Test Finished\n")
# Facade
class TestRunner:
def __init__(self):
self.tc1 = TC1()
self.tc2 = TC2()
self.tc3 = TC3()
self.tests = [self.tc1, self.tc2, self.tc3]
def runAll(self):
[i.run() for i in self.tests]
# Client
if __name__ == '__main__':
testrunner = TestRunner()
testrunner.runAll()
# ---- OUTPUT: ---- :
#
# ###### In Test 1 ######
# Setting up
# Running test
# Tearing down
# Test Finished
#
# ###### In Test 2 ######
# Setting up
# Running test
# Tearing down
# Test Finished
#
# ###### In Test 3 ######
# Setting up
# Running test
# Tearing down
# Test Finished