interface Factory {
public static function getDB(); //接口里的类不用实现,下面的子类来具体实现
}
class mysqlFactory implements Factory {
public static function getDB() {
return new MySQL();
}
}
class SqliteFactory implements Factory {
public static function getDB() {
return new Sqlite();
}
}
class MyPDOFactory implements Factory {
public static function getDB() {
return new MyPDO();
}
}
// 配置文件
$fact = ‘MyPDOFactory‘;
$db = MyPDOFactory::getDB();
print_r($db);