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
+17-19Lines changed: 17 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,17 +15,17 @@ __What is a Design Pattern ?__
15
15
16
16
__Java Design Patterns__ are divived into tree parts : *Creational*, *Structural* and *Behavioral*.
17
17
18
-
# CREATIONAL DESIGN PATTERNS
18
+
##CREATIONAL DESIGN PATTERNS
19
19
20
20
Creational design pattens provide solution to instatiate an object in the best possible way for specific situations.
21
21
The basic form of object creation could result in design problems or add unwanted complexity to the design. Creational design patterns solve this problem by __controlling the object creation__ by different ways.
22
-
There are five creational design patterns that we will discuss :
22
+
There are five creational design patterns that we will discuss on :
23
23
24
-
1 .Singleton Pattern
25
-
2. Factory Pattern
26
-
3. Abstract Factory Pattern
27
-
4. Builder Pattern
28
-
4. Prototype Pattern
24
+
*Singleton Pattern
25
+
* Factory Pattern
26
+
* Abstract Factory Pattern
27
+
* Builder Pattern
28
+
* Prototype Pattern
29
29
30
30
### Pattern Singleton
31
31
@@ -63,17 +63,14 @@ We'll implement the thread safe one here. Classes are in the package `com.single
63
63
64
64
Factory design pattern is used when we have a super class with multiple sub-classes and based on input, we need to return one of the sub-class. This pattern take out the responsibility of instantiation of a class from client program to the factory class. Let’s first learn how to implement factory pattern in java and then we will learn its benefits and we will see its usage in JDK.
65
65
66
-
* Super Class
67
-
Super class in factory pattern can be an interface, abstract class or a normaljava class. For our example, we have super class as abstract class with overridden toString() method for testing purpose.
68
-
see `com.factory`.
69
-
* sub-classes
70
-
Let’s say we have two sub-classes PC and Server with implementation in `com.factory`
71
-
72
-
Here's what we have in image :
73
-
[](http://zupimages.net/up/17/13/7w9z.png)
74
-
75
-
76
-
Now let's write the test class.
66
+
* Super Class
67
+
Super class in factory pattern can be an interface, abstract class or a normaljava class. For our example, we have super class as abstract class with overridden toString() method for testing purpose.
68
+
see `com.factory`.
69
+
* sub-classes
70
+
Let’s say we have two sub-classes PC and Server with implementation in `com.factory`
71
+
Here's what we have in image :
72
+
[](http://zupimages.net/up/17/13/7w9z.png)
73
+
Now let's write the test class.
77
74
78
75
```java
79
76
importcom.factory.FactoryClass ; //The factory class
@@ -214,5 +211,6 @@ public class PrototypePatternTest {
0 commit comments