Should I make this a singleton?
Hi, been a while since my last post. Been busy with a project.
Okay here's the question. I have an object that should only have an instance. But the object should not be created with the default constructor. It's because to create the object, the programmer should define the parameters of the creation of the object. I was thinking of doing this:
With this code, e.g., if I wanted to call method a, should call it with:
CObject * getInstance(param A, param B, param C, ...); //To get the instance of the object and create it if it wasn't already created
static CObject * mTheObject;
CObject(param A, param B, param C,...);
CObject * CObject::getInstance(param A, param B, param C, ...)
mTheObject=new CObject(param A, param B, param C, ...);
But getting the instance with parameters that just only needed once to create the object is not too efficient so I was hesitant to implement it. I could just make it a generic one and just make sure I didn't make it more than once throughout my code. But I just wanted to see a different approach in this. Any idea?
CObject::getInstance(param A, param B, param C, ...)->methodA();
Thanks in advance.