设计模式--单例模式

<?php
class Preferences {
    private static $instance;

    private function __construct() { }

    public static function getInstance() {
        if (empty(self::$instance)) {
            self::$instance = new Preferences();
        }
        return self::$instance;
    }
}


//CLIENT CODE
$pref = Preferences::getInstance();

单例模式

posted @ 2015-09-04 16:21  wy0314  阅读(93)  评论(0)    收藏  举报