Implementowanie formalnego interfejsu z ABC
W tym ćwiczeniu przećwiczysz implementowanie formalnego interfejsu utworzonego za pomocą klasy ABC i dekoratora @abstractmethod. Interfejs Business został już dla ciebie przygotowany i jest pokazany poniżej. Powodzenia!
class Business(ABC):
@abstractmethod
def sell_product(self, product_name, price, quantity):
pass
To ćwiczenie jest częścią kursu
Programowanie obiektowe w Pythonie – poziom średnio zaawansowany
Interaktywne ćwiczenie praktyczne
Spróbuj tego ćwiczenia, uzupełniając ten przykładowy kod.
# Create a class that inherits the Business interface
class ____(____):
def __init__(self, business_name):
self.business_name = business_name
# Attempt to create a Bakery object, observe the exception
____:
blue_eyed_baker = ____("Blue Eyed Baker")
____ Exception ____ e:
print(____)