Design Patterns2011. 12. 6. 18:08

마지막 생성 패턴이다.
이건 머 말할것도 없다. 유일 객체 생성~ 


struct MonsterManager
{
public:
    MonsterManager() {cout << "This is MonsterManager !!!" << endl;};
};

////////////

template 
class Singleton
{
public:
    static T* Instance()
    {
        if (NULL == instance_)
        {
            instance_ = new T;
        }
        return instance_;
    }

    static void Release()
    {
        if (instance_) 
        {		
            delete instance_;
            instance_ = NULL;
        }
    }

private:

    static T* instance_;
};

template< class T > T * Singleton::instance_ = NULL;

void main()
{   
    Singleton::Instance();    
    Singleton::Release();
    Singleton::Instance();    
}


This is MonsterManager !!!
This is MonsterManager !!!

'Design Patterns' 카테고리의 다른 글

POSA1 Layers Architecture pttern  (0) 2013.07.02
Bridge Patten (브릿지 패턴)  (0) 2011.12.13
Prototype  (0) 2011.12.05
Factory Method  (0) 2011.11.16
Builder  (0) 2011.11.15
Posted by 상현달