标签:
# coding=utf-8
这种方式反倒把事情做复杂了 可取之处在于有了更高层次的抽象
class IEmployee:
def insert_employee(self):
pass
class ICompany:
def insert_company(self):
pass
# mysql版本的数据库访问
class EmployeeMysql(IEmployee):
def insert_employee(self):
print "插入员工mysql数据库"
class CompanyMysql(ICompany):
def insert_company(self):
print "插入公司mysql数据库"
class EmployeeMSSQL(IEmployee):
def insert_employee(self):
print "插入员工sqlserver数据库"
class CompanyMSSQL(ICompany):
def insert_company(self):
print "插入公司sqlserver数据库"
class IFactory:
def insert_employee(self):
pass
def insert_company(self):
pass
class FactoryMySQL(IFactory):
def insert_employee(self):
temp = EmployeeMysql()
return temp
def insert_company(self):
temp = CompanyMysql()
return temp
class FactoryMSSQL(IFactory):
def insert_employee(self):
temp = EmployeeMSSQL()
return temp
def insert_company(self):
temp = CompanyMSSQL()
return temp
if __name__ == "__main__":
factory = FactoryMSSQL()
employee = factory.insert_employee()
insert_company = factory.insert_company()
employee.insert_employee()
insert_company.insert_company()
标签:
原文地址:http://www.cnblogs.com/zijiyanxi/p/5277940.html