# 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()