Click here to Skip to main content
15,890,399 members
Home / Discussions / C#
   

C#

 
GeneralRe: Thread-Safe Singleton Pin
Paul Evans8-Dec-03 7:20
Paul Evans8-Dec-03 7:20 
GeneralRe: Thread-Safe Singleton Pin
Heath Stewart8-Dec-03 10:08
protectorHeath Stewart8-Dec-03 10:08 
GeneralRe: Thread-Safe Singleton Pin
bzurer8-Dec-03 7:07
bzurer8-Dec-03 7:07 
GeneralRe: Thread-Safe Singleton Pin
Heath Stewart8-Dec-03 7:10
protectorHeath Stewart8-Dec-03 7:10 
GeneralRe: Thread-Safe Singleton Pin
bzurer8-Dec-03 7:56
bzurer8-Dec-03 7:56 
GeneralRe: Thread-Safe Singleton Pin
Heath Stewart8-Dec-03 9:14
protectorHeath Stewart8-Dec-03 9:14 
GeneralRe: Thread-Safe Singleton Pin
Zhang Ye Fan8-Dec-03 7:33
Zhang Ye Fan8-Dec-03 7:33 
GeneralRe: Thread-Safe Singleton Pin
Heath Stewart8-Dec-03 9:08
protectorHeath Stewart8-Dec-03 9:08 
There's a difference between singletons and a class with static methods. If you just have simple static methods (like the System.Math class), you don't need to construct a singleton. Singletons are useful when you want lots of different callers to use the same resource without having multiple instances of that resource (or the class that has that resource). For instance, all throughout the .NET BCL (and our application I architected), most classes in an assembly use a internal singleton that has a single instance of a ResourceManager that contains strings (and other resources at times) for all classes to use (like common exception messages or property categories and descriptions). It would be horribly inefficient to have an instance of this ResourceManager for each class (and who knows how many instances of each class?!), so they use a singleton with a single instance of the ResourceManager.

There are many other reasons for singletons (if you know anything about remoting, there's some good examples for that, too). This is just a common example I think of because I use it a lot and it is far more efficient to do it this way that for each instance of a class to have it's own - especially when you're sharing string resources amongst other classes.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: Thread-Safe Singleton Pin
bzurer11-Dec-03 3:31
bzurer11-Dec-03 3:31 
GeneralRe: Thread-Safe Singleton Pin
Heath Stewart11-Dec-03 4:30
protectorHeath Stewart11-Dec-03 4:30 
GeneralRe: Thread-Safe Singleton Pin
bzurer11-Dec-03 4:56
bzurer11-Dec-03 4:56 
Generalabout setup projects Pin
Mauricio Ritter8-Dec-03 3:50
Mauricio Ritter8-Dec-03 3:50 
GeneralRe: about setup projects Pin
Heath Stewart8-Dec-03 3:55
protectorHeath Stewart8-Dec-03 3:55 
GeneralRe: about setup projects Pin
Mauricio Ritter8-Dec-03 4:20
Mauricio Ritter8-Dec-03 4:20 
GeneralRe: about setup projects Pin
Heath Stewart8-Dec-03 4:52
protectorHeath Stewart8-Dec-03 4:52 
QuestionAbout Collections? Pin
E#8-Dec-03 3:29
sussE#8-Dec-03 3:29 
AnswerRe: About Collections? Pin
E#8-Dec-03 3:31
sussE#8-Dec-03 3:31 
AnswerRe: About Collections? Pin
Heath Stewart8-Dec-03 3:52
protectorHeath Stewart8-Dec-03 3:52 
GeneralRe: About Collections? Pin
leppie8-Dec-03 6:19
leppie8-Dec-03 6:19 
GeneralRe: About Collections? Pin
Heath Stewart8-Dec-03 6:22
protectorHeath Stewart8-Dec-03 6:22 
QuestionOR? Pin
eggie58-Dec-03 3:22
eggie58-Dec-03 3:22 
AnswerRe: OR? Pin
Heath Stewart8-Dec-03 3:47
protectorHeath Stewart8-Dec-03 3:47 
GeneralRe: OR? Pin
eggie58-Dec-03 11:39
eggie58-Dec-03 11:39 
GeneralRe: OR? Pin
Heath Stewart8-Dec-03 11:41
protectorHeath Stewart8-Dec-03 11:41 
GeneralRe: OR? Pin
eggie58-Dec-03 11:45
eggie58-Dec-03 11:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.