如果里面没有任何抽象方法,那么在 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 (将#修改为@)