为操作数据库设计增删改查操作
# 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:
dbmanager = {}
dbmanager['Insert'] = DbInsert()
dbmanager['Del'] = DbDel()
dbmanager['Update'] = DbUpdate()
dbmanager['Query'] = DbQuery()
def create_dbmanager(self, operate):
if operate in self.dbmanager:
op = self.dbmanager[operate]
else:
op = UnDef()
return op
if __name__ == "__main__":
operate = raw_input("输入操作: ")
factory = DbManagerFactory()
fac = factory.create_dbmanager(operate)
print fac.operate_db()