class Super:
def method(self):
print ‘in Super.method’
def delegate(self):
self.action()
class Inheritor(Super):
pass
class Replacer(Super):
def method(self):
print ‘in Replacer.method’
class Extender(Super):
def method(self):
print ‘starting Extender.method’
Super.method(self)
print ‘ending Extender.method’
class Provider(Super):
def action(self):
print ‘in Provider.action’
if __name__ == ‘__main__’:
for klass in (Inheritor, Replacer, Extender):
print ‘\n’ + klass.__name__ + ‘…’
klass().method()
print ‘\nProvider…’
x = Provider()
x.delegate()
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。