Python设计模式(3)-工厂方法模式
2016-03-13 21:19
621 查看
# coding=utf-8 #定义一个用于创建对象的接口,让子类决定实例化哪一个类 class DbManager: def __init__(self): pass def operate_db(self): pass class DbInsert(DbManager): def operate_db(self): print '插入操作' class DbDel(DbManager): def operate_db(self): print '删除操作' class DbUpdate(DbManager): def operate_db(self): print '更新操作' class DbQuery(DbManager): def operate_db(self): print '查询操作' class UnDef(DbManager): def operate_db(self): print '未实现' return 0 class DbManagerFactory: def createdbmanagerfactory(self): manager = DbManager() return manager class InsertFactory(DbManagerFactory):
def createdbmanagerfactory(self): manager = DbInsert() return manager class DelFactory(DbManagerFactory): def createdbmanagerfactory(self):
manager = DbDel() return manager if __name__ == "__main__": fac = InsertFactory() fa = fac.createdbmanagerfactory() print fa.operate_db()
相关文章推荐
- python(5) - time模块
- leetcode 337. House Robber III-动态规划|Java|Python简洁高效
- Python设计模式(2)-策略模式
- python笔记之字符串格式化
- Python代码风格的良好养成
- Python设计模式(1)-简单工厂模式
- python闭包
- python(5)–sys模块
- Ubuntu 部署Python开发环境
- Python之Django-part 1
- python函数参数注意事项
- python中有关numpy的
- python--文本处理1
- PythonChallenge Mission 5
- python(5)-os模块
- 深度学习进行时间序列模式识别
- python爬取网站图片
- PythonChallenge Mission 4
- Python开发接水果小游戏
- Python面向对象编程