因为 Python 没有提供抽象类, 需要使用抽象类需要使用 abc 模块
abc 用法很简单主要是 3 个:
ABCMeta,abstactporperty,abstractmethod
- from abc import ABCMeat, abstractporperty, abstractmethod
- class B():
- __metaclass__ = ABCMeta
- @abstractporperty
- def map_data(self):
- pass
- @abstractmethod
- def find(self):
- pass
子类中必须重写抽象方法.
来源: