设计模式 模版模式

class CarTemplate:
    def __init__(self):
        pass
    def wheel(self):
        return ('4个轮子,牌子是:');
    def engine(self):
        return ('一个发动机,牌子是:')
    def frame(self):
        return ('一个车架,牌子是:')

    def show(self):
        self.wheel()
        self.engine()
        self.frame()

class BMWCar(CarTemplate):
    def wheel(self):
        print(super().wheel() + '宝马')

    def engine(self):
        print(super().engine() + '宝马')
    def frame(self):
        print(super().frame() + '宝马')

class AuditWCar(CarTemplate):
    def wheel(self):
        print(super().wheel() + '奥迪')

    def engine(self):
        print(super().engine() + '奥迪')
    def frame(self):
        print(super().frame() + '奥迪')

if __name__=='__main__':
    car = BMWCar()
    car.show()
    car = AuditWCar()
    car.show()
原文地址:https://www.cnblogs.com/agang-php/p/9969292.html