C++实现设计模式: Singleton 单例模式
来源:互联网 发布:xd破解id软件 编辑:程序博客网 时间:2024/06/10 03:45
注:
又一次仔细读了刘未鹏写的《暗时间》,总结自己之所以在编程方面成长不理想的原因就是自己花在总结上的时间太少了,总是写过的代码和用过的模式很快就忘记了,有点过分依赖参考资料和Google.因此,今天起陆续总结一下自己使用过的一些设计模式,不过由于C++设计模式方面的资料很少,我将坚持采用C++语言说明。
目前自己能够熟练使用的模式大概有:Singleton, Factory,Adapter, Proxy, Facade,Observer, Decorator,Strategy, Template。
第一回:Singleton
SingletonExecutor.h
class SingletonExecutor
{
private:
SingletonExecutor();
~SingletonExecutor();
SingletonExecutor(const SingletonExecutor&);
SingletonExecutor& operator=(const SingletonExecutor&);
public:
static SingletonExecutor& GetInstance();
}
SingletonExecutor.cpp
SingletonExecutor& SingletonExecutor::GetInstance()
{
static SingletonExecutor* sInstance = NULL;
if ( !sInstance)
{
Mutex mutex;
ScopedLock(&mutex);
if (!sInstance)
{
sInstance = new SingletonExecutor();
}
}
return *sInstance;
}
//In fect use the default constructor is OK.
SingletonExecutor::SingletonExecutor(void)
{
//
}
//There is no need destructor because the singleton object should exist throughout the program life cycle.
Announce in advance:
下期博客,敬请期待:
设计模式前传 之 你所不知道的构造函数
- Objective C 实现Singleton(单例)模式.
- c++--Singleton单例模式的实现
- 乐在其中设计模式(C#) - 单例模式(Singleton Pattern)
- 单例设计模式(Singleton)
- 单例设计模式Singleton
- singleton(单例设计模式)
- 单例设计模式(Singleton)
- Singleton 单例设计模式
- 单例设计模式Singleton
- Singleton 单例设计模式
- Singleton单例设计模式
- 单例(Singleton)设计模式
- 设计模式-Singleton单例
- 单例(Singleton)设计模式
- 设计模式之—单例模式(Singleton)-Java实现
- C++实现设计模式: Singleton 单例模式
- 设计模式实现(十七)---单例模式(SingleTon)
- 设计模式之单例模式(Singleton Pattern)C++实现
- ubuntu11.10 make android 4.0.3
- 模拟电路与数字电路的区别
- Java值传递以及引用的传递、数组的传递!!
- 其它机可以, 但本机无法上传
- cuda ubuntu install
- C++实现设计模式: Singleton 单例模式
- Apache中 RewriteCond 规则参数介绍
- FTP数字的含义
- java时间操作
- vim(四) 使用技巧之缩进,选择,高亮
- USB-2404系列,电压、温度和基于电桥的输入模块
- Android开发中颜色的定义方法
- Android AlertDialog
- s5pv210_gpio驱动及其在android2.3.1下jni调用