zoukankan      html  css  js  c++  java
  • 设计模式 模版模式

    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()
  • 相关阅读:
    Codeforces_739_B
    Codeforces_732_D
    D
    C
    E
    商汤AI园区的n个路口(中等)
    D. The Fair Nut and the Best Path
    HDU6446
    分解质因数(线性筛)
    D. Extra Element
  • 原文地址:https://www.cnblogs.com/agang-php/p/9969292.html
Copyright © 2011-2022 走看看