# Coding=utf-8
It's a way of making things more complicated. The merit is that there is a higher level of abstraction
Class IEmployee:
def insert_employee (self):
Pass
Class Icompany:
def insert_company (self):
Pass
# MySQL version of database access
Class Employeemysql (IEmployee):
def insert_employee (self):
Print "Insert employee MySQL database"
Class Companymysql (Icompany):
def insert_company (self):
Print "Insert company MySQL database"
Class Employeemssql (IEmployee):
def insert_employee (self):
Print "Insert Employee SQL Server Database"
Class Companymssql (Icompany):
def insert_company (self):
print "Insert company SQL Server Database"
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 design pattern (8)-Abstract Factory