----------------------------------------------------------- New Message on BDOTNET
----------------------------------------------------------- From: SitaramanM Message 5 in Discussion Hi Sailesh : In the pre-.Net world the coding u have given was necessary. In fact the standard way t o implement a Singleton is as u had given, i.e. a) Create a Class b) Have a private Data member with the type same as the declaring class c) Have a private constructor d) have a public method which will lazy-initialize the private member and return it This is the way itis implemented in a Java program also. However this leads to some problems in terms of locking and the solution was given by using the Double Checked Locking Mechanism.The worst part is that Java compilers mess up with the code and result in a unreliable behaviour :) [Check out "The "Double-Checked Locking is Broken" Declaration " at http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html] That said, MS, obviously and as usual, offers a much simpler and fool-proof way to implement a singleton in Singleton. No more private members, locking business etc... All u have to do to create a singleton is this : // .NET Singleton sealed class Singleton { private Singleton() {} public static readonly Singleton Instance = new Singleton(); } This will create a Singleton Class. Check out this nice material on Singleton at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/singletondespatt.asp Soumitra : Could not understand ur exact reqmt. If you can post an explanation(as to whether u need a COM Component or a .Net component launched from a COM+ Server), probably i could help u out regards, sr ----------------------------------------------------------- To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. http://groups.msn.com/BDotNet/_emailsettings.msnw Need help? If you've forgotten your password, please go to Passport Member Services. http://groups.msn.com/_passportredir.msnw?ppmprop=help For other questions or feedback, go to our Contact Us page. http://groups.msn.com/contact If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. mailto:[EMAIL PROTECTED]
