I have a base class which is abstract. However, every object of this type will hold a value val
.
In the derived class, I will then have an __init__
function. This function does NOT take the value val
as input, it just knows it by definition.
class Base(ABC):
pass
class Derived(Base):
def __init__(self):
self.val = 5
All sub-classes of Base
will have this val
, and they will all set it internally, i.e. it won't be an argument. However now if I am using inheritance, nobody knows that Base
-objects have val
.
So how am I meant to structure this code, so that users now that if its a Base
-object, it will have val
. Do I use class variables somehow? Or do I need to give Base
an __init__
even though it is an abstract method? And how should that __init__
be structured, given that derived classes don't take any parameters in their __init__
?