Here's the tea: I'm writing a small Monopoly game using python. I've made this little class family to represent the bills. There's a base abstract class
called Bill which inherits from the abc.ABC
class.
Code:
from abc import ABC, abstractmethod
import colorama
colorama.init(autoreset=True, strip=True)
class Bill(ABC):
#Abstract Properties (must be overriden in subclasses)
@property
@abstractmethod
def count(self):
return 0
@property
@abstractmethod
def color(self): # colorama background color
return 0
@property
@abstractmethod
def worth(self): # integer representing the bill's worth
return 0
# Dunder methods (The same across class family)
def __add__(self, other):
return self.worth + other.worth
def __str__(self):
return f" {self.color} {self.worth}"
class One(Bill):
def __init__(self):
self.__count = 0
self.__color = "\033[0m"
self.__worth = 0
#super().init() ??
# Override Abstract Methods
@property
def count(self):
return self.__count
@count.setter
def count(self, amount):
self.__count += 1
@property
def worth(self):
return 1
@property
def color(self):
return colorama.Back.WHITE
My question is whether my subclasses will inherit the Bill
class's dunder methods.
And if not, do I need to include super().__init__()
in the One
class's __init__
method?