Design Pattern 4 (second round of abstract factory pattern)

Source: Internet
Author: User

In the first round.

First, create a department class. Assume that there are only two fields: department ID and department name.

       ID { ;   DeptName { ; 

The following shows the UML class diagram of the Department table.

IDpartment interface, used for client access to remove coupling with specific database access.

    

SqlServerDepartment class, used to access the Department of SQL Server.

       Department GetDepartment( 

AccessDepartment class, used to Access the Departmet of Access.

       Department GetDepartment( 

Ifacloud interface, which defines an abstract factory interface for creating access Department table objects.

    

The CreateDepartment () interface method is added to the ifacloud interface.

The SqlServerFactory class implements the ifacloud interface, which is mainly used to implement the Department interface method added to the SQL Server database.

       

AccessFactory class to implement the ifacloud interface. It is mainly used to implement the Department interface method added to the Access database.

       

Client code

      Main(= = = ==

If you want to switch the database, you only need IFactory factory =
Only when there is one Uer class and one User operation class, only the factory method mode is required. But now you obviously have a lot of tables in your database, and SQL Server and Access are two different types, therefore, to solve this problem involving multiple product series, there is a special factory model called abstract factory model.

Through the first round and the second round of the prelude, we can finally enter the subject.

 

Related Article

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.