<?php interface db{ public function conn(); } interface Factory{ public function createDb(); } class dbmysql implements db{ public function conn(){ echo "连上mysql"; } } class mysqlFactory extends Factory{ public function createDb(){ return new dbmysql(); } } class dboracle implements db{ public function conn(){ echo "连上了oracle"; } } class oracleFactory implements Factory{ public function createDb(){ return new dboracle(); } } //客户端调用 $fact= new mysqlFactory(); $db=$fact->createDb(); $db->conn(); ?>