I have a Base class that is inherited by two classes Adder and subtractor in which I have overridden the method called test_func() to adapt to respective class properties.
class Base():
def __init__(self, K):
self.K = K
def test_func(self):
'Must be overridden since used by another_func()'
return self.K
def another_func(self):
return self.K * self.test_func()
class Adder(Base):
def __init__(self, K, M):
Base.__init__(self, K)
self.M = M
def test_func(self):
return self.M + self.K
class Subtractor(Base):
def __init__(self, K, N):
Base.__init__(self, K)
self.N = N
def test_func(self):
return self.N - self.K
I am writing a superclass called Algebra that inherits both Adder and Subtractor.
class Algebra(Adder, Subtractor):
def __init__(self, K, M, N):
Adder.__init__(self, K, M)
Subtractor.__init__(self, K, N)
Now I want to use the test_func() method selectively from Adder or Subtractor in the superclass Algebra. Is there a way in which I can do this? I tried
G = Algebra(K=2, M=5, N=7)
G.test_func()
>> 7
but it only takes method from Adder class. Is ther a way I can tell the superclass which class to evaluate the method from? For example,
G.test_func('Adder')