单例模式2014/3/27

写一个简单是单例模式的例子

class Pattern{
    Private $array=array();
    private Static $instance;
    Private function __construct(){

    }
    public static function getInstance(){
        if(empty(self::$instance)){
            self::$instance=new Pattern();
        }   
        return self::$instance;
    }  
    public function setArray($key,$value){
        $this->array[$key]=$value;   
    } 
    public function getArray($key){
        return $this->array[$key];   
    }              
}

 

posted @ 2014-03-27 11:02  FookLook  阅读(109)  评论(0编辑  收藏  举报