“”“单例模式”“”
“”“工厂模式”“”文章来源:https://www.toymoban.com/news/detail-621194.html
class Person:
pass
class Worker(Person):
pass
class Student(Person):
pass
class Teacher(Person):
pass
class Factory:
def get_person(self, p_type):
if p_type == 'w':
return Worker()
elif p_type == 's':
return Student()
else:
return Teacher()
pf = Factory()
worker = pf.get_person('w')
stu = pf.get_person('s')
teacher = pf.get_person('t')
文章来源地址https://www.toymoban.com/news/detail-621194.html
到了这里,关于python_day16_设计模式的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!