In Python, I have an abstract base class which has four methods, of which at least one has to be overwritten. Is it possible to somehow implement this with the @abstractmethod
decorator or something similar?
Here is a stripped down version of the base class:
from abc import ABCMeta
class Base(metaclass=ABCMeta):
def __init__(self, var):
self.var = var
def a(self, r):
return self.var - self.b(r)
def b(self, r):
return self.var * self.c(r)
def c(self, r):
return 1. - self.d(r)
def d(self, r):
return self.a(r) / self.var
The four methods have some kind of cyclic dependency and a subclass has to override at least one of these methods. The rest of the methods then work from the base class.
It might seem a bit strange, but it makes perfectly sense in the application I'm working on.