python_day16_设计模式

"""单例模式"""

"""工厂模式"""

python 复制代码
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')
相关推荐
大吱佬38 分钟前
GO 八股整理(自用)
开发语言·后端·golang
froginwe111 小时前
Go 语言结构体
开发语言
vx_vxbs661 小时前
【SSM高校普法系统】(免费领源码+演示录像)|可做计算机毕设Java、Python、PHP、小程序APP、C#、爬虫大数据、单片机、文案
android·java·python·mysql·小程序·php·idea
松涛和鸣1 小时前
DAY20 Optimizing VS Code for C/C++ Development on Ubuntu
linux·c语言·开发语言·c++·嵌入式硬件·ubuntu
田里的水稻1 小时前
Python_编程中代码注释相关格式 PEP8 — Python 官方代码风格指南
开发语言·python
一只乔哇噻1 小时前
java后端工程师+AI大模型进修ing(研一版‖day57)
java·开发语言·人工智能·算法·语言模型
Williams101 小时前
Java POI/Excel工具:终结OOM、精度丢失和i18n三大难题
java·开发语言·excel
丹宇码农1 小时前
consul集群搭建
python·consul
李绍熹1 小时前
Lua 错误处理详解
开发语言·junit·lua
I***26151 小时前
PHP进阶-在Ubuntu上搭建LAMP环境教程
开发语言·ubuntu·php