Please enable JavaScript.
Coggle requires JavaScript to display documents.
SINGLETON PATTERN - Coggle Diagram
SINGLETON PATTERN
-
-
-
CODE
- class Singleton
{
private static Singleton instance;
//Constructor
private Singleton()
{}
public static Singleton GetInst(){}
}
-
Singleton.GetInstance()
return new Singleton
Since we are in the singleton class it doesn't matter that the constructor is private, we have access to the constructor
Method Logic
- Check if the static variable is null
- We instantiate the singleton and we store it in the variable
- If we have the singleton we return the variable