Skip to content

Commit ff2742b

Browse files
committed
add Facade pattern
1 parent c3648ea commit ff2742b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

facade/Facade.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Python Design Patterns: Facade
3+
# Author: Jakub Vojvoda [github.com/JakubVojvoda]
4+
# 2016
5+
#
6+
# Source code is licensed under MIT License
7+
# (for more details see LICENSE)
8+
#
9+
10+
import sys
11+
12+
#
13+
# Subsystems
14+
# implement more complex subsystem functionality
15+
# and have no knowledge of the facade
16+
#
17+
class SubsystemA:
18+
def suboperation(self):
19+
print("Subsystem A method")
20+
21+
class SubsystemB:
22+
def suboperation(self):
23+
print("Subsystem B method")
24+
25+
class SubsystemC:
26+
def suboperation(self):
27+
print("Subsystem C method")
28+
29+
#
30+
# Facade
31+
# delegates client requests to appropriate subsystem object
32+
# and unified interface that is easier to use
33+
#
34+
class Facade:
35+
def __init__(self):
36+
self._subA = SubsystemA()
37+
self._subB = SubsystemB()
38+
self._subC = SubsystemC()
39+
40+
def operation1(self):
41+
self._subA.suboperation()
42+
self._subB.suboperation()
43+
44+
def operation2(self):
45+
self._subC.suboperation()
46+
47+
48+
if __name__ == "__main__":
49+
facade = Facade()
50+
facade.operation1()
51+
facade.operation2()

0 commit comments

Comments
 (0)