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