Code structure diagram:
Abstract Factory Definition: Abstract Factory mode provides an interface to create a series of related or interdependent objects without specifying their specific class (official definition look at the real egg hurt yourself Baidu understand ^_^)
Requirements: Different database SQL syntax, implementation from different databases to get users and new users, access to departments and new departments
User Table Abstract Product A
Class user{
}
Department Table abstract Product B
Class department{
}
Interface for decoupling the definition of a specific abstract product
Interface iuser{
Public function Insert (user $user);
Public Function GetUser ($id);
}
Class Mysqluser implements iuser{
Public function Insert (user $user) {
Echo ' Adds a record <br/> ' to the user table in MySQL;
}
Public Function GetUser ($id) {
Echo ' Gets a record of the user table in MySQL by id <br/> ';
}
}
Class Sqlserveruser implements iuser{
Public function Insert (user $user) {
Echo ' Adds a record <br/> ' to the user table in Sqlserve;
}
Public Function GetUser ($id) {
Echo ' Gets a record of the user table in the Sqlserve by ID <br/> ';
}
}
Department decoupling defines interfaces for specific abstract products
Interface idepartment{
Public Function Insert (department $d);
Public Function getdepartment ($id);
}
Class Mysqldepartment implements idepartment{
Public Function Insert (department $d) {
Echo ' Adds a record <br/> ' to the department table in MySQL;
}
Public Function Getdepartment ($id) {
Echo ' Gets a record of the department table in MySQL based on id <br/> ';
}
}
Class Sqlserverdepartment implements idepartment{
Public Function Insert (department $d) {
Echo ' Adds a record <br/> ' to the Department table in SQL Server;
}
Public Function Getdepartment ($id) {
Echo ' Gets a record of the department table in SQL Server based on ID <br/> ';
}
}
Factory method
Interface factory{
Public function CreateUser ();
Public function createdepartment ();
}
Specific Factory class
Class Mysqlfactory implements factory{
Public Function CreateUser () {
return new Mysqluser ();
}
Public Function createdepartment () {
return new Mysqldepartment ();
}
}
Specific Factory class
Class Sqlserverfactory implements factory{
Public Function CreateUser () {
return new Sqlserveruser ();
}
Public Function createdepartment () {
return new Sqlserverdepartment ();
}
}
Client
Class client{
Public function Show () {
$user = new User (); User table
$dept = new Department (); Department table
 
$factory = new Mysqlfactory (); MySQL specific factory class It's just so easy to change the factory class here.
$u = $factory->createuser ();
$u->insert ($user);
$u->getuser (1);
$d = $factory->createdepartment ();
$d->insert ($dept);
$d->getdepartment (1);
}
}
$n = new Client ();
$n->show ();
All the original blog has been verified by me, I Caishuxueqian, just started to write a blog I hope you have a lot of support problems, please point out that I promptly correct
 PHP design Mode---Abstract mode mode