python中简单工厂实现demo

 1 class BenBen:
 2     def __init__(self, money):
 3         """
 4         奔奔金融支付
 5         :param money:支付金额 
 6         """
 7         self.money = money
 8 
 9     def pay(self):
10         print("收到奔奔金融支付金额{0}".format(self.money))
11 
12 
13 class WeChat:
14     def __init__(self, money):
15         """
16         微信支付
17         :param money:支付金额 
18         """
19         self.money = money
20 
21     def pay(self):
22         print("收到微信支付金额{0}".format(self.money))
23 
24 
25 class ZhiFuBao:
26     def __init__(self, money):
27         """
28         支付宝支付
29         :param money:支付金额 
30         """
31         self.money = money
32 
33     def pay(self):
34         print("收到支付宝支付金额{0}".format(self.money))
35 
36 
37 if __name__ == '__main__':
38     channel = input("请选择支付方式:")
39     money = input("请输入消费金额:")
40     if channel == 'WeChat':
41         WeChat(money).pay()
42     elif channel == 'ZhiFuBao':
43         ZhiFuBao(money).pay()
44     else:
45         BenBen(money).pay()
posted @ 2020-01-06 20:04  奔奔-武  阅读(390)  评论(0编辑  收藏  举报