Re: [Dev-C++] Design decision in C++
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-03-09 23:50:23
|
I would instanciate a single object using the singleton design pattern.
Make the only constructor private, and add a public static method to
create and retrieve this single instance:
class MyClass {
private:
static My>Class *myself;
MyClass(); // Note constructor private!
public:
static MyClass* getInstance() {
if (!myself) myself =3D new MyClass;
return myself;
}
};
/Per W
On Tue, 9 Mar 2004, Michael Stather wrote:
> Hi,
>
> I=B4ve thought about a class-design for one of my projects.
> I=B4ve several big codeblocks like "compiler" which are seperated into
> classes.
> However, of this classes there is only one instance, like TheCompiler.
> So I thought of implementing this class using static methods rather than =
a
> regular class (I don=B4t need constructors/destructors).
> So, is it better do use a regular class and create one instance of it or =
to
> use a class which has only static methods (also easier)
> Where are the caveats?
>
> thanks for your help
>
> Michael Stather
>
|