By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,896 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,896 IT Pros & Developers. It's quick & easy.

singleton classes !!

P: n/a
I want to make a class that :

- will have one and only one object
- when you try to make another object of this class , an IDE error should be
seen . like using undefined variable , or any thing like that ..
Sep 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hadidi,

The first part is easy, and I'm sure you know the singleton pattern, so
there is no reason to repeat it here.

As for the second part, that's nearly impossible. If you are asking for
an IDE error, you are asking for a compile-time error, and there is no way
to do something like this. The best you could do is settle for a run time
error.

However, if you implement the singleton correctly, you will end up
making your constructor private, and you will have definite control over the
lifetime of the instance, and won't have to worry about someone else
creating the object.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Hadidi" <Ha****@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...
>I want to make a class that :

- will have one and only one object
- when you try to make another object of this class , an IDE error should
be
seen . like using undefined variable , or any thing like that ..

Sep 21 '06 #2

P: n/a
User defined compile time errors can be generated with #error directive. I
don't think this will help the OP

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:ud**************@TK2MSFTNGP02.phx.gbl...
Hadidi,

The first part is easy, and I'm sure you know the singleton pattern, so
there is no reason to repeat it here.

As for the second part, that's nearly impossible. If you are asking
for an IDE error, you are asking for a compile-time error, and there is no
way to do something like this. The best you could do is settle for a run
time error.

However, if you implement the singleton correctly, you will end up
making your constructor private, and you will have definite control over
the lifetime of the instance, and won't have to worry about someone else
creating the object.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Hadidi" <Ha****@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...
>>I want to make a class that :

- will have one and only one object
- when you try to make another object of this class , an IDE error should
be
seen . like using undefined variable , or any thing like that ..


Sep 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.