PRIVATE CONSTRUCTORS CAN BE USED IN THE SINGLETON DESIGN PATTERN

Chris S

Total Post:23

Points:115
Posted by  Chris S
Java  OOPS 
 1044  View(s)
Ratings:
Rate this:
  1. Chris S

    Post:23

    Points:115
    Private constructors can be used in the singleton design pattern

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!