I have an abstract class that i will use as template to implement different kind of subclasses. I want to define some attributes/methods that are mandatory to all subclasses. For example
class BlockModel(ABC):
def __init__(self, position):
self.__position = position
self.__lives = None
self.__hitbox = None
@property
def lives(self):
return self.__lives
@lives.setter
def lives(self, lives):
self.__lives = lives
@property
def hitbox(self):
return self.__hitbox
@hitbox.setter
def hitbox(self, hitbox):
self.__hitbox = hitbox
@abstractmethod
def method1(self)
#some abstract methods
@abstractmethod
def method2(self)
#some abstract methods
When i create a subclass, for example
class Block1(BlockModel):
def __init__(self,position_):
super().__init__(position_)
self.__lives=1
self.__hitbox = pygame.Rect(self.__position['x'],
self.__position['y'],
5,
5)
#Implement abstract methods
The second class doesn't inherit the attributes __position
, __lives
, __hitbox
, but the public ones without the underscores (i know that there are no real private attributes/methods in python). There s a way too keep them private(with underscores) in the subclass too?