class Super:
def method(self):
print('super method')
def delegate(self):
self.action()
class Inheritor(Super): #1 获得父类的一切内容
pass
class Replacer(Super): #2 覆盖父类的method
def method(self):
print('replacer.method')
class Extender(Super): #3 覆盖并回调method 定制父类的method方法
def method(self):
print('extender.method')
Super.method(self)
print('ending extend.method')
class Provider(Super): #4
def action(self): # 实现super的delegate方法预期的action方法
print('provider.action')
if __name__ == '__main__':
for i in (Inheritor,Replacer,Extender):
print(i.__name__)
i().method()
x = Provider()
x.delegate()
'''
Inheritor
super method
provider.action
Replacer
replacer.method
provider.action
Extender
extender.method
super method
ending extend.method
provider.action
'''
python类接口,了解一下
最新推荐文章于 2024-08-08 17:05:27 发布