The website had the code written in c++ but i used converted to make it python
from abc import ABC, abstractmethod
class Door(ABC):
@abstractmethod
def get_width(self):
pass
@abstractmethod
def get_height(self):
pass
class WoodenDoor(Door):
def __init__(self, width, height):
self.width = width
self.height = height
def get_width(self):
return self.width
def get_height(self):
return self.height
class DoorFactory:
@staticmethod
def make_door(width, height):
return WoodenDoor(width, height)
# Make me a door of 100x200
door = DoorFactory.make_door(100, 200)
print('Width:', door.get_width())
print('Height:', door.get_height())
# Make me a door of 50x100
door2 = DoorFactory.make_door(50, 100)
Can anyone explain me more about the asbtract method? I dont understand why its used in the inheritance but never is called super. Also why this pattern is good and why its usefull? I think many people reading this code would say why not call it directly and remove the factory code