Python抽象工厂模式实现
2017-09-03 20:06
155 查看
# -*- 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实现设计模式--03.抽象工厂模式(Abstract Factory Pattern)
- python中利用KNN实现对iris进行分类
- python数据结构之链表——基本操作实现
- python3 flask实现文件上传功能
- python实现归并排序
- Python获取linux主机ip的简单实现方法
- 用Python实现一个简单的能够发送带附件的邮件程序的教程
- Python实现的二分查找
- 使用python实现二维数组反转90度
- 【机器学习算法实现】logistic回归__基于Python和Numpy函数库
- Linux守护进程设计规范及python实现http://blog.csdn.net/dysj4099/article/details/18219411
- 基于信息增益的决策树归纳的Python实现【CD4.5算法】
- C语言代码格式自动化(python实现)
- 【Python笔记】递归函数实现汉诺塔移动
- python实现旋转和水平翻转的方法
- 计算1-10^12之间所有数的约数的和的python实现
- 推荐一个机器学习框架——python实现
- python和shell实现的校验IP地址合法性脚本分享
- python下paramiko模块实现ssh连接登录Linux服务器
- python递归实现快速排序