PHP-设计模式-单例模式

时间:2014-06-28 00:12:03   收藏:0   阅读:228

实用场景




编号场景
1数据库连接
2

bubuko.com,布布扣

<?php
/**
 * PHP设计模式-单例模式
 * @author chengtao3
 */
class Singleton{
	private static $Instance = null;
	/**
	 * 公共静态方法获取实例
	 * @return Singleton
	 */
	public function getInstance(){
		if(self::$Instance == null){
			self::$Instance = new Singleton();
		}
		return self::$Instance;
	}
	/**
	 * 屏蔽__clone方法,
	 * 单例模式,只有一个对象,如果使用了clone则可以复制,
	 * 因此屏蔽__clone方法
	 */
	public function __clone(){}
}


本文出自 “程涛的博客” 博客,转载请与作者联系!

PHP-设计模式-单例模式,布布扣,bubuko.com

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!