0 Star 0 Fork 0

大海真强/pythonLearn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
02-设计4S店.py 865 Bytes
一键复制 编辑 原始数据 按行查看 历史
大海真强 提交于 2018-07-18 23:19 +08:00 . ti'提提
class Factory(object):
def select_car_by_type(self,car_type):
if car_type == "索纳塔":
# 用一个对象里的方法返回对象
return Suonata()
elif car_type == "明途":
return MingTu()
class CarStore(object):
def __init__(self):
self.factory=Factory()
def order(self,car_type):
#解耦
return self.factory.select_car_by_type(car_type)
class Car(object):
def move(self):
print("车子在移动")
def music(self):
print("车子在放音乐")
def stop(self):
print("车子在制动")
class Suonata(Car):
def introduce(self):
print("我是索纳塔")
class MingTu(Car):
def introduce(self):
print("我是明途")
car_store=CarStore()
car=car_store.order("明途")
car.move()
car.music()
car.stop()
car.introduce()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dahaizhenqiang/pythonLearn.git
git@gitee.com:dahaizhenqiang/pythonLearn.git
dahaizhenqiang
pythonLearn
pythonLearn
master

搜索帮助