abstractmethod

a class with an abstract method cannot be instantiated (that is, we cannot create an instance by calling it) unless all of its abstract methods have been defined in subclasses. Although this requires more code and extra knowledge, the potential advantage of this approach is that errors for missing methods are issued when we attempt to make an instance of the class, not later when we try to call a missing method. This feature may also be used to define an expected interface, automatically verified in client classes.

如果在父类中使用@abstractmethod,那么子类中必须明确定义这个abstract method才能实例化,否则会报错。

使用@abstractmethod的优点是,避免子类在编程过程中漏掉必要的method

Java 中也有类似方法。

转载于:https://www.cnblogs.com/yaos/p/7101982.html

你可能感兴趣的:(abstractmethod)