天天看點

類設計:設計賣車的4S店                                                                   -------  知識無價,汗水有情,如需搬運請注明出處,謝謝!

class Car(object):
    # 定義車的方法
    def move(self):
        print('---車在移動---')
    def stop(self):
        print('---停車---')

# 定義一個銷售車的店類
class CarStore(object):
    def order(self):
        car = Car() # 找一輛車
        return car

# 1.先得有個銷售汽車的店鋪
car_store = CarStore()
# car_store.order().move()
# 2.通過這家店訂車
my_car = car_store.order()
# 3.開車爽
my_car.move()
my_car.stop()
      

  

                                                                   -------  知識無價,汗水有情,如需搬運請注明出處,謝謝!

繼續閱讀