In Python, how can I use a concrete method of an abstract class in the inherited class?

23 Views Asked by At

So I have an abstract class which has one non-abstract (concrete) method:

class abstract_class(ABC):
    def __init__(self) -> None:
        self.a = 0
        self.b = 0

    def new_method(self):
        self.a = 1
        self.b  = 1

Now, I have another abstract class, which inherits from the abstract_class:

class inherited_class (ABC, abstract_class):
    def __init__(self) -> None:
        super().__init__()
        self.c = 0

    def new_method(self):
    #to_do

Here is my question: both "new_method" methods are concrete. I want the second new_method to do everything the super class's new_method does, and in addition to that, does also this: self.c = 1

What is the best way to achieve that?

I tried this:

    def new_method(self):
        self.a = 1
        self.b  = 1
        self.c = 1

But I doubt if it's the best idea.

0

There are 0 best solutions below