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
+70-3Lines changed: 70 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,7 @@ __Java Design Patterns__ are divived into tree parts : *Creational*, *Structural
28
28
4. Prototype Pattern
29
29
30
30
### Pattern Singleton
31
+
31
32
Pattern Singleton: > One Class, one Instance.
32
33
Singleton is one of the Gangs of Four Design patterns and comes in the Creational Design Pattern category.
33
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__.
@@ -102,7 +103,7 @@ Factory design pattern is used when we have a super class with multiple sub-clas
102
103
* java.util.Calendar, ResourceBundle() and NumberFormat getInstance();
103
104
* valueOf() method in wrapper classes like Boolean , Integer etc.
104
105
105
-
# Abstract Factory
106
+
###Abstract Factory
106
107
107
108
This is one of the Creational Pattern and almost similar to Factory Pattern except the fact that it's most like
108
109
Factory of factories.
@@ -126,7 +127,7 @@ Factory of factories.
126
127
```
127
128
128
129
129
-
# Pattern Builder
130
+
###Pattern Builder
130
131
131
132
Builder pattern is a creational design pattern as Factory Pattern and Abstract Factory Pattern. This pattern was introduced to solve some of the problems with Factory and Abstract Factory patterns when the Object contains a lot of attributes. This pattern deals with a static nested class and then copy all the arguments from the outer class to the Builder class.
132
133
The sample code where we have a Computer class and ComputerBuilder to build it are available in the package `com.builder.Computer`.
@@ -148,4 +149,70 @@ public class TestBuilderPattenr{
148
149
149
150
}
150
151
```
151
-
There are really various implementations of this pattern in JDK.
152
+
There are really various implementations of this pattern in JDK : java.lang.StringBuilder#append() (unsynchronized) java.lang.StringBuffer#append() (synchronized) .
153
+
154
+
### Pattern Prototype
155
+
156
+
Prototype pattern is one of the Creational Design pattern, so it provides a mechanism of object creation. Prototype pattern is used when the Object creation is a costly affair and requires a lot of time and resources and you have a similar object already existing. So this pattern provides a mechanism to copy the original object to a new object and then modify it according to our needs. This pattern uses java cloning to copy the object.
0 commit comments