"""
Script introduction:
    - 属性的使用
        -使用已有方法定义访问器/修改器/删除器

@Time :       2018-08-05 20:16
@Author :     nulijiushimeili
@Site :       
@File :       car2.py
@Software :   PyCharm
"""


class Car(object):
    def __init__(self, brand, max_speed):
        self.set_brand(brand)
        self.set_max_speed(max_speed)

    def get_brand(self):
        return self._brand

    def get_max_speed(self):
        return self._max_brand

    def set_brand(self, brand):
        self._brand = brand

    def set_max_speed(self, max_speed):
        if max_speed < 0:
            raise ValueError("Invalid max speed for car.")
        self._max_brand = max_speed

    def __str__(self):
        return "Car: [brand=%s,max_speed=%d]" % (self._brand,self._max_brand)

    # 用已有的修改器和访问器定义属性
    brand = property(get_brand,set_brand)
    max_speed = property(get_max_speed,set_max_speed)


if __name__ == "__main__":
    car = Car("QQ",120)
    car.max_speed = 320
    car.brand = "Benz"
    car.current_speed = 160
    print(car)
    print(Car.brand)
    print(Car.brand.fget)
    print(Car.brand.fset)