Home > DeveloperSection > Interviews > Private constructors can be used in the singleton design pattern

Posted on    February-23-2015 2:48 AM

 1 Answer(s)
  911  View(s)
Rate this:

Chris S
Chris S

Total Post:23

Posted on    February-23-2015 3:48 AM

Why would you want objects of your class to only be created internally? This could be done for any reason, but one possible reason is that you want to implement a singleton. A singleton is a design pattern that allows only one instance of your class to be created, and this can be accomplished by using a private constructor.The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance.

Modified On Mar-21-2016 07:05:07 AM

Don't want to miss updates? Please click the below button!

Follow MindStick