|
Subject:
|
private constructor in C#
|
|
Posted By:
|
n.nsivakumar
|
Post Date:
|
8/16/2006 3:29:14 AM
|
Hello p2p's
i want to know what is the use of declaring the constructors as private or protected.
[N.Sivakumar]
|
|
Reply By:
|
adam_kahtava
|
Reply Date:
|
8/16/2006 7:08:50 AM
|
Private or protected constructors are generally used to restrict instantiation of a class to a single object. This is often done through the Singleton design pattern.
Private constructors can also be useful for: classes containing only static utility methods classes containing only constants type safe enumerations
Links of further interest: The Singleton pattern: http://en.wikipedia.org/wiki/Singleton_pattern. Private Constructors: http://www.javapractices.com/Topic40.cjp
- Adam Kahtava [http://adam.kahtava.com]
|