桥接模式

class Car:
    def __init__(self, obj):
        self.color = obj()

    def showColor(self):
        return self.color.show()


class BMW(Car):
    def showColor(self):
        print('bmw')
        return super().showColor()

class Audi(Car):
    def showColor(self):
        print('audi')
        return super().showColor()

class Color:
    def __init__(self):
        pass
    def show(self):
        pass

class White(Color):
    test = '333'
    def show(self):
        return 'white'

class Red(Color):
    def show(self):
        return 'red'

car = BMW(White)
print(car.showColor())
car = Audi(Red)
print(car.showColor())

posted @ 2018-11-07 15:03  agang_19  阅读(108)  评论(0)    收藏  举报