当前位置:天才代写 > tutorial > Python教程 > python的设计模式

python的设计模式

2018-05-18 08:00 星期五 所属: Python教程 浏览:472

python">
# encoding=utf-8  
def printInfo(info):  
    print unicode(info, 'utf-8').encode('gbk')  

class Person():  
    name = ""  

    def __init__(self, name):  
        self.name = name;  
        return;  

    def Show(self):  
        printInfo("zhuangbanhao%s" % self.name)  
class Finery(Person):  
    component = None  

    def __init__(self):  
        return;  

    def Decorate(self, component):  
        self.component = component  

    def Show(self):  
        if(None != self.component):  
            self.component.Show()  

class BigTrouser(Finery):  
    def Show(self):  
        printInfo("ku_zi")    
        self.component.Show()        

class TShirts(Finery):  
    def Show(self):  
        printInfo("t_shirt")  
        self.component.Show()  

def clientUI():  
    xc = Person("xiaocai")  
    bT = BigTrouser()  
    TS = TShirts()  
    bT.Decorate(xc)  
    TS.Decorate(bT)  
    TS.Show()  
    return  

if __name__ == '__main__':  
    clientUI(); 

标签:python

 

    关键字:

天才代写-代写联系方式