python类接口,了解一下

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

'''
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值