interface db{ function conn(); } interface Factary{ function createDb(); } //服务端开发 class dbmysql implements db{ function conn(){ echo "连上了Mysql"; } } class dbsqlite implements db{ function conn(){ echo "连上了sqlite"; } } class mysqlFactory implements Factary{ function createDb(){ return new dbmysql(); } } class sqliteFactory implements Factary{ function createDb(){ return new dbsqlite(); } } //客户端开始 $fact = new mysqlFactory(); $db = $fact->createDb(); $db->conn(); $fact = new sqliteFactory(); $db = $fact->createDb(); $db->conn();
09-10
09-10