Skip to main content

Posts

Showing posts with the label singleton

Creational Patterns : Singleton

Properties: -            Ensures that only one instance is created. -            Global access is provided to single instance. -            Conventionally has a  public static  method named  getInstance/getXYZ  ,where XYZ stands for class name, to return the class instance. -            Suitable for creating factory instances and system wide unique resources. Implementation: -            Constructor should be made  private/protected  to prevent arbitrary instance creation. -            Single instance is created and assigned to a  public static  member of the class. This class member is conventionally named as  instance ...