Blogger Information
Blog 6
fans 3
comment 1
visits 8854
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
设计模式之单例模式
齐天大圣的博客
Original
1456 people have browsed it

单例模式应该是设计模式里最容易理解的设计模式了,它主要解决的就是资源浪费问题,一个类只允许一个实例化

class Database
{
    protected static $db = null;


    private function __construct()
    {
    }


    public static function getInstance ()
    {
        if (is_null(self::$db)) {
            self::$db = new self;
        }


        return self::$db;
    }
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post