抽象工廠模式

interface Factory {
public static function getDB();   //接口裏的類不用實現,下面的子類來具體實現
}接口

class MySQLFactory implements Factory {
public static function getDB() {
return new MySQL();
}
}get

class SqliteFactory implements Factory {
public static function getDB() {
return new Sqlite();
}
}it

class MyPDOFactory implements Factory {
public static function getDB() {
return new MyPDO();
}
}io


// 配置文件
$fact = 'MyPDOFactory';
$db = MyPDOFactory::getDB();
print_r($db);function

相關文章
相關標籤/搜索