我需要类似于Python(3.2)中的抽象保护
方法:
class Abstract:
def use_concrete_implementation(self):
print(self._concrete_method())
def _concrete_method(self):
raise NotImplementedError()
class Concrete(Abstract):
def _concrete_method(self):
return 2 * 3
定义一个"抽象"方法只为了引发NotImplementedError,这真的有用吗?
在Python中,使用下划线来表示抽象方法,这是良好的编程风格吗?在其他语言中,这些方法通常被视为受保护的。
使用抽象基类(abc)是否会改善任何问题?
NotImplementedError
呢? - deamonclass Abstract(metaclass=ABCMeta)
只能在 Python 3 中使用,是吗? - clstaudt