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]

Go to topic 48432

Return to index page 202
Return to index page 201
Return to index page 200
Return to index page 199
Return to index page 198
Return to index page 197
Return to index page 196
Return to index page 195
Return to index page 194
Return to index page 193