始める無料で始める

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(____)
コードを編集して実行