使用 ABC 實作正式介面
在這個練習中,你將實作一個用 ABC 類別與 @abstractmethod 裝飾器建立的正式介面。Business 介面已為你建立,如下所示。加油!
class Business(ABC):
@abstractmethod
def sell_product(self, product_name, price, quantity):
pass
本練習屬於課程
Python 物件導向程式設計進階
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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(____)