| 1 | package CreationalDesignPattern.SingletonDesignPattern; |
| 2 | |
| 3 | public class Singleton { |
| 4 | //Step1: We have created a private constructor of Singleton class & it can only be instantiated within this class. |
| 5 | private Singleton(){ |
| 6 | } |
| 7 | |
| 8 | //Step2: Create a static var to hold one instance of Singleton class. |
| 9 | |
| 10 | private static Singleton uniqueInstance; |
| 11 | |
| 12 | //Step3: Create a static getInstance() method to instantiate the class and also to return an instance of it. |
| 13 | |
| 14 | public static Singleton getInstance(){ |
| 15 | if (uniqueInstance == null){ |
| 16 | uniqueInstance = new Singleton(); |
| 17 | } |
| 18 | return uniqueInstance; |
| 19 | } |
| 20 | |
| 21 | //other useful methods here. |
| 22 | } |
nothing calls this directly
no outgoing calls
no test coverage detected