????:<?phpclass Db() {//私有的靜態(tài)變量用于存儲(chǔ)實(shí)例對(duì)象 private static $instance=null;//s私有化構(gòu)造函數(shù),不能在類(lèi)外部new實(shí)例化
<?php
class Db()
{
//私有的靜態(tài)變量用于存儲(chǔ)實(shí)例對(duì)象
private static $instance=null;
//s私有化構(gòu)造函數(shù),不能在類(lèi)外部new實(shí)例化
private function __construct(){}
//外部實(shí)例化接口
public static function getInstance()
{
if(is_null(static::$instance))
{
static::$instance=new static();
}
return static::$instance
}
}
?>
?? ???:西門(mén)大官人?? ??:2019-04-08 09:51:30
???? ??:設(shè)計(jì)模式通常都有固定的寫(xiě)法,記住各常見(jiàn)設(shè)計(jì)模式的寫(xiě)法和其適用場(chǎng)景后,可以寫(xiě)出質(zhì)量更高的代碼