python的设计模式

2015-09-09 0 858
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 python的设计模式 http://www.ox520.com/15764.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务