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.