: This article mainly introduces the abstract Factory mode in php. if you are interested in the PHP Tutorial, refer to it. Abstract factory model
The difference between it and the factory method mode is that the abstract factory is to first create a factory, and then the factory is creating a product (instance );
Defines an interface for creating objects, so that the subclass determines which class is instantiated. He can solve the closed and open principles in the simple factory model;
// Product (database) standard interface DbInterface {public function connect (Array $ params = array (); public function query ($ SQL); public function insert ($ table, $ record); public function update ($ table, $ record, $ where); public function delete ($ table, $ where) ;}// specific product (Mysql) class MysqlDb implements DbInterface () {public function connect (Array $ params = array (); public function query ($ SQL) {} public function insert ($ table, $ record) {} public function update ($ table, $ record, $ where) {} public function delete ($ table, $ where) {}} class implements aldb implements DbInterface () {public function connect (Array $ params = array () {} public function query ($ SQL) {} public function insert ($ table, $ record) {} public function update ($ table, $ record, $ where) {} public function delete ($ table, $ where) {}// construct the factory interface CreateFactory () {function createDB (); // divided into restrained and outgoing} class FactoryMysql implements CreateFactory {function createDB () {return new MysqlDb ();}} class FactoryOracle implements CreateFactory {function createDB () {return new externaldb () ;}( 1) if you want to use mysql $ db = new FactoryMysql ()-> createDB ();//
The above introduces the abstract factory model in php, including some content, and hope to be helpful to friends who are interested in PHP tutorials.