假设我有一个ABC:
class Template_ABC(metaclass=abc.ABCMeta):
def __init__(self, data=None, model=None):
self._data = data
self._model = model
@abc.abstractmethod
def do_stuff(self):
pass
@abc.abstractmethod
def do_more_stuff(self):
pass
我通常有一类ABC,例如:
class Example_of_ABC(Template_ABC):
def do_stuff(self):
# Do stuff here
def do_more_stuff(self):
pass
现在,我想将Example-of_ABC类作为子类。我唯一可以做的方法如下:
class Subclass_of_Example_of_ABC(Example_of_ABC):
def __init__(self, data=None, model=None):
super().__init__(data, model)
def do_more_stuff(self):
# Do more stuff here
这种方式的问题是,我必须为ABC的每个子类更新def _init __()。无论如何,子类是否可以继承ABC的所有init?