You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,7 @@ Pattern Singleton: > One Class, one Instance.
34
34
Singleton pattern restricts the instantiation of a class and ensures that only one instance of the class exists in the java virtual machine. The singleton class must provide a global access point to get the instance of the class. Singleton pattern is used for logging, driver objects, caching and thread pool. Singleton design pattern is also used in other design patterns like __Abstract Factory__, __Builder__, __Prototype__, __Facade__ etc. Singleton design pattern is used in core java classes also, for example __java.lang.Runtime__ , __java.awt.Desktop__.
35
35
36
36
To implement Singleton pattern, there are really many approaches but all of them have following common concepts:
37
+
37
38
* A private constructor to avoid instantiation of the class,
38
39
* A private static variable from the same class that's the only instance of the class.
39
40
* public static method that returns the instance of the class, this is the global access point for the outer world to
@@ -91,7 +92,8 @@ Factory design pattern is used when we have a super class with multiple sub-clas
91
92
//Now you can see the output in your console.
92
93
}
93
94
```
94
-
This pattern provides some advantages such as :
95
+
This pattern provides some advantages such as :
96
+
95
97
* It provides approach to code for the interface rathan than the implementation.
96
98
* It removes the instantiation of the actual implementation classes from client code, making it more robust.
97
99
* It provides abstraction between implementation and client classes through inheritance.
0 commit comments