#!/usr/local/python3.5/bin/python3.5


####实现方法一
class Supper(object):
    def delegate(self):
        self.action()

    def action(self):
        raise NotImplementedError("you must implement Supper.action function")

class Sub(Supper):
    pass
        

####实现方法二

from abc import ABCMeta
from abc import abstractmethod

class Supper2(metaclass=ABCMeta):
    def delegate(self):
        self.action()
    @abstractmethod
    def action(self):
        pass

class Sub2(Supper2):
    def action(self):
        print('hello world!')
    




if __name__=="__main__":

    s=Sub2()
    s.delegate();
    

 

相关文章:

  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2021-12-15
  • 2021-09-11
猜你喜欢
  • 2022-01-19
  • 2022-02-11
  • 2021-11-05
  • 2021-06-12
  • 2022-12-23
  • 2021-07-24
  • 2021-10-10
相关资源
相似解决方案