forked from amirbigg/python-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacade.py
More file actions
37 lines (25 loc) · 633 Bytes
/
facade.py
File metadata and controls
37 lines (25 loc) · 633 Bytes
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
"""
Facade
- a structural design pattern that provides a simplified interface to a library,
a framework, or any other complex set of classes.
"""
class CPU: # Subsystem 1
def execute(self):
print('Executing')
class Memory: # Subsystem 2
def load(self):
print('Loading data.')
class SSD: # Subsystem 3
def read(self):
print('Some data from ssd')
class Computer: # Facade
def __init__(self, sub1, sub2):
self.cpu = sub1()
self.memory = sub2()
def start(self):
self.memory.load()
self.cpu.execute()
def client_facade():
computer_facade = Computer(CPU, Memory)
computer_facade.start()
client_facade()