Let's assume that we have a Python class that makes use of the abc module to define an abstract attribute:
import abc
class A(object):
__metaclass__ = abc.ABCMeta
@abc.abstractproperty
def test_attribute(self):
raise NotImplementedError
Let's now consider to define B
that subclasses from A
by adding a new method (test_method()
), and C
that subclasses from B
implementing the abstract method originally declared in A
:
class B(A):
def test_method(self):
pass
class C(B):
def test_attribute(self):
# Implement abstract attribute
pass
Assuming that I would like to keep B
abstract (non-instantiable), shall I redefine the abstract property (test_attribute
) and the metaclass assignment also in B
? Or is it enough to inherit them from A
(as in the above code)?
I know that Python allows me to not redefine the abstract methods and thus inherit them from the parent class. Is this correct from a theoretical software engineering perspective?
I'm asking so because if I'm not wrong other languages (such as Java) do not allow inheritance of abstract methods without reimplementing them as abstract...