Building a formal interface with ABC
Formal interfaces offer a more enforceable contract between an interface and any classes that implement it. You'll practice creating a formal interface made up of two abstract methods, using the abc module. The ABC class and abstractmethod decorator have been imported from abc. Have fun!
Bu egzersiz
Intermediate Object-Oriented Programming in Python
kursunun bir parçasıdırEgzersiz talimatları
- Create a formal interface, called
Product. - Define
purchase()as an abstract method with parametersselfandquantity, and add thepasskeyword to the method body. - Define the
update_price()abstract method, which takes parametersselfandnew_price.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Create a Product interface
____ ____(____):
# Define a purchase() abstract method
____
def ____(____, quantity):
____
# Create an update_price() abstract method
____
def ____(self, ____):
____