设计一个卖不同种类车的4s店

时间:2023-03-09 09:22:10
设计一个卖不同种类车的4s店
# 定义奔驰车类
class BenchiCar(object):
# 定义车的方法
def move(self):
print('---奔驰车在移动---')
def stop(self):
print('---奔驰车停车了---') # 定义宝马车类
class BMWCar(object):
# 定义车的方法
def move(self):
print('---宝马车在移动---') def stop(self):
print('---宝马车停车了---') # 定义一个销售北京现代车的店类
class CarStore(object):
def order(self, typeName):
if typeName == '奔驰':
car = BenchiCar() # 找一辆车
elif typeName == '宝马':
car = BMWCar() # 找一辆车
return car pinpai_store = CarStore()
my_car = pinpai_store.order('宝马')
my_car.move()
my_car.stop() # 这样做,不太好,因为当北京现代又生产一种新类型的车时,那么又得在CarStore类中修改