J
JohnQ
Why would anyone write:
class SomeThing // class littered with non-domain single-instancing code
{
private:
SomeThing();
static SomeThing* pInstance_;
public:
static SomeThing* getInstance()
{
if(!pInstance_)
{
pInstance_ = new SomeThing();
}
return pInstance_;
}
};
SomeThing* SomeThing:Instance_ = 0;
instead of this:
class SomeThing // class unencumbered by single-instancing concerns
{
public:
SomeThing();
};
SomeThing* GetSomeThing() // single-instancing accessor function
{
static SomeThing* thing = new SomeThing();
return thing;
}
???
Is it because the second example only solves the problem but doesn't ensure
that someone won't call the constructor elsewhere? That's it isn't it.
Single-instance techniques help with the initialization order problem, and
the second form works great for that. I don't think single instance control
belongs in a domain class. 'SingleInstancer' should be a template class.
What's your opinion?
John
class SomeThing // class littered with non-domain single-instancing code
{
private:
SomeThing();
static SomeThing* pInstance_;
public:
static SomeThing* getInstance()
{
if(!pInstance_)
{
pInstance_ = new SomeThing();
}
return pInstance_;
}
};
SomeThing* SomeThing:Instance_ = 0;
instead of this:
class SomeThing // class unencumbered by single-instancing concerns
{
public:
SomeThing();
};
SomeThing* GetSomeThing() // single-instancing accessor function
{
static SomeThing* thing = new SomeThing();
return thing;
}
???
Is it because the second example only solves the problem but doesn't ensure
that someone won't call the constructor elsewhere? That's it isn't it.
Single-instance techniques help with the initialization order problem, and
the second form works great for that. I don't think single instance control
belongs in a domain class. 'SingleInstancer' should be a template class.
What's your opinion?
John