proxydemo2.py

来自「this is the most basic to learn python」· Python 代码 · 共 26 行

PY
26
字号
#: c04:ProxyDemo2.py
# Simple demonstration of the Proxy pattern.

class Implementation2:
  def f(self): 
    print "Implementation.f()"
  def g(self): 
    print "Implementation.g()" 
  def h(self): 
    print "Implementation.h()" 

class Proxy2:
  def __init__(self): 
    self.__implementation = Implementation2() 
  def __getattr__(self, name):
    return getattr(self.__implementation, name)

p = Proxy2()
p.f(); p.g(); p.h();
#<hr>
output = '''
Implementation.f()
Implementation.g()
Implementation.h()
'''

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?