python----抽象类

#!/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();
    

 

posted on 2016-08-02 18:32  蒋乐兴的技术随笔  阅读(219)  评论(0编辑  收藏  举报

导航