class Payment(object):
def __init__(self):
pass
def give_money(self):
pass
def give_ok(self):
pass
class alipay(Payment):
def __init__(self):
print('支付宝ing')
def give_money(self):
print('支付宝支付中')
print('...')
def give_ok(self):
print('支付宝支付成功')
class wxpay(Payment):
def __init__(self):
print('微信ing')
def give_money(self):
print('微信支付中')
print('...')
def give_ok(self):
print('微信支付成功')
class Paymentmethod(object):
def method(self, method):
if method == '微信':
return wxpay()
elif method == '支付宝':
return alipay()
Pay = Paymentmethod()
Pay.method('支付宝')
# 支付宝ing
通过工厂来创建类的实例