# -*- coding:utf-8 -*-
'''
Created on 2017.9.3
@author: dell
'''
#注意 python动态的语言 类的属性不一定的被实例所共享
class Item(object):
caption = ''
def __init__(self,caption):
print "Item caption "+caption
self.caption = caption
def makeHTML(self):
pass
def getCaption(self):
return self.caption
class Link(Item):
url = ''
def __init__(self,caption,url):
print "Link caption "+caption
Item.__init__(self,caption)
self.url = url
def getCaption(self):
return self.caption
class ListLink(Link):
def __init__(self,caption,url):
print "ListLink caption "+ caption
Link.__init__(self,caption,url)
def makeHTML(self):
# print super(ListLink,self).getCaption()
return "<a>"+self.caption+"</a>"
class Factory(object):
def createLink(self,caption,url):
pass
class ListFactory(Factory):
def createLink(self,caption,url):
return ListLink(caption,url)
factory = ListFactory()
l1 = factory.createLink("Hello,Word", "Factory")
print l1.makeHTML()
print l1.__dict__
Python抽象工厂模式实现
最新推荐文章于 2023-02-08 16:29:07 发布