设计模式-结构型模式之代理

解耦调用方与被调用方之间的关系

 1 class Valley:
 2 
 3     def test(self):
 4         print(1)
 5 
 6 
 7 class Proxy:
 8     """代理类"""
 9 
10     def __init__(self, real_obj):
11         self.proxy = real_obj
12 
13     def func(self):
14         self.proxy.test()
15 
16 
17 if __name__ == '__main__':
18     Proxy(Valley()).func()

 

posted on 2022-09-22 22:56  默玖  阅读(11)  评论(0编辑  收藏  举报

导航