Is it a good practice to put common methods to an abstract class in Python?

4162 views python

I'm using the abc module to define an interface that subclasses must support. There're also some common methods that are present in all subclasses. Is it ok to put them in the abstract class or should that only contain abstract methods (i.e. decorated with @abc.abstractmethod) ?

answered question

Typically the difference between an interface and an abstract class is that interface does not have fields and does not have any methods implemented. Both concepts are useful depending on context. In Python there is no clear distinction though.

1 Answer


Why not just use raise NotImplementedError

class ParentInterface:

    def common_method(args):
        raise NotImplementedError('Implement this in child class')

posted this

Have an answer?


Please login first before posting an answer.