"""
工厂模式
"""
class NoodleFactory(object):
def __init__(self):
pass
def CreateNoodel(self, sType):
if sType == "拉面":
LaNoodle()
elif sType == "泡面":
PaoNoodle()
elif sType == "炸酱面":
ZhajiangNoodle()
elif sType == "热干面":
ReganNoodle()
class LaNoodle():
def __init__(self):
print("点了一碗拉面")
class PaoNoodle():
def __init__(self):
print("点了一碗泡面")
class ZhajiangNoodle():
def __init__(self):
print("点了一碗炸酱面")
class ReganNoodle():
def __init__(self):
print("点了一碗热干面")
pFactory = NoodleFactory()
lLst = ["泡面", "热干面", "拉面", "炸酱面"]
for sType in lLst:
pFactory.CreateNoodel(sType)
"""
点了一碗泡面
点了一碗热干面
点了一碗拉面
点了一碗炸酱面
"""
07-17
220
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-14
943
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-14
797
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交