python中的虚函数

2015-09-05 0 487
python中的虚函数
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()

遇见资源网 python python中的虚函数 http://www.ox520.com/15741.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务