Skip to content

Commit 5fb6788

Browse files
committedOct 8, 2019
no message
1 parent d29f169 commit 5fb6788

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
 

‎结构型模式-外观模式.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
# @Author : ydf
3+
# @Time : 2019/10/8 0008 19:00
4+
"""
5+
外观模式(Facade Pattern)隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口。这种类型的设计模式属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性。
6+
7+
这种模式涉及到一个单一的类,该类提供了客户端请求的简化方法和对现有系统类方法的委托调用。
8+
"""
9+
10+
from monkey_print2 import print
11+
12+
class A:
13+
def run(self):
14+
print('A run')
15+
16+
def jump(self):
17+
print('A jump')
18+
19+
20+
class B:
21+
def run(self):
22+
print('B run')
23+
24+
def jump(self):
25+
print('B jump')
26+
27+
28+
class C:
29+
def run(self):
30+
print('C run')
31+
32+
def jump(self):
33+
print('C jump')
34+
35+
36+
class Facade:
37+
def __init__(self):
38+
self.a = A()
39+
self.b = B()
40+
self.c = C()
41+
42+
def run(self):
43+
for item in ('a', 'b', 'c'):
44+
getattr(self, item).run()
45+
46+
def jump(self):
47+
for item in ('a', 'b', 'c'):
48+
getattr(self, item).jump()
49+
50+
51+
if __name__ == '__main__':
52+
facade = Facade()
53+
facade.run()
54+
facade.jump()

0 commit comments

Comments
 (0)
Please sign in to comment.