码迷,mamicode.com
首页 > 编程语言 > 详细

Python设计模式(8)-抽象工厂

时间:2016-03-15 08:38:51      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

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

Python设计模式(8)-抽象工厂

标签:

原文地址:http://www.cnblogs.com/zijiyanxi/p/5277940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!