from abc import ABCMeta,abstractmethod
class payment(metaclass=ABCMeta): # 抽象类:所有的继承抽象类的子类必须有抽象类定义的方法,否则报错
@abstractmethod
def pay(self):
pass
class Alipay(payment):
def __init__(self,money):
self.money = money
def pay(self):
print('使用阿里支付了%s' % self.money)
class Jdpay(payment):
def __init__(self,money):
self.money = money
def pay(self):
print('使用京东支付了%s' % self.money)
def pay(obj): # 定义一个函数,统一调用接口
obj.pay()
a1 = Alipay(200)
j1 = Jdpay(100)
pay(a1)
pay(j1)