如何解决如果里面没有任何抽象方法,那么在 Python 中继承 ABC Class 有什么意义吗?
# For simplicity,we are not defining getter and setter functions. The reader can
# assume that all class attributes are private and accessed through their respective
# public getter methods and modified only through their public methods function.
class Account:
def __init__(self,user_name,password,name,email,phone,shipping_address,status=AccountStatus):
self.__user_name = user_name
self.__password = password
self.__name = name
self.__email = email
self.__phone = phone
self.__shipping_address = shipping_address
self.__status = status.ACTIVE
self.__credit_cards = []
self.__bank_accounts = []
def add_product(self,product):
None
def add_productReview(self,review):
None
def reset_password(self):
None
from abc import ABC,abstractmethod
class Customer(ABC):
def __init__(self,cart,order):
self.__cart = cart
self.__order = order
def get_shopping_cart(self):
return self.__cart
def add_item_to_cart(self,item):
None
def remove_item_from_cart(self,item):
None
class Guest(Customer):
def register_account(self):
None
class Member(Customer):
def __init__(self,account):
self.__account = account
def place_order(self,order):
None
我在网上学习 Python 的面向对象设计课程时遇到了这个问题。 因此,如果您查看 Customer 类,它们继承了 ABC 但其中没有抽象方法。
如果我错了,请纠正我,但我们为父类继承 ABC 的唯一原因是为将来继承父类的类提供结构,对吗?
那么如果里面没有抽象类,那还有什么意义呢?或者他们只是在为未来做好准备?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。