Python design pattern (8)-Abstract Factory

Source: Internet
Author: User

# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.