1
- # Java Designs Pattern
1
+ # Java Design Patterns
2
2
3
3
Here's is an implementation of some Design Patterns from scratch : p
4
4
@@ -44,8 +44,7 @@ Pattern Singleton: One Class, one Instance.
44
44
There are many implementations of this pattern, but we will implement the Thread Safe one.
45
45
Classes are in the package ` com.Singleton ` ;
46
46
47
- ```java
48
-
47
+ ```java
49
48
import com.singleton.SingletonThreadSafe;
50
49
51
50
public class SingletonTest {
@@ -63,7 +62,8 @@ Classes are in the package `com.Singleton`;
63
62
//Now check out your console.... What the hell, the two instances have the same reference :o
64
63
}
65
64
}
66
- ```
65
+ ```
66
+
67
67
# Pattern Factory
68
68
69
69
Factory Pattern is one of the Creational Design pattern and it's widely used in JDK as well as frameworks like
@@ -86,4 +86,25 @@ This pattern is used when we have a super class with multiple sub-classes and ba
86
86
Computer comp2 = fc.getComputer("Server",30,900,9);
87
87
System.out.println(comp2);
88
88
89
+ //Now you can see the output in your console.
90
+ }
91
+ ```
92
+
93
+ # Abstract Factory
94
+
95
+ This is one of the Creational Pattern and almost similar to Factory Pattern except the fact that it's most like
96
+ Factory of factories.
97
+ Source files are in the package ` com.abstractFactory ` .
98
+
99
+ ``` java
100
+
101
+ public class abstractFactoryTest {
102
+ public static void main (String [] args ){
103
+
104
+ Computer c = ComputerFactory . getComputer(new PCFactory (" 4G" ," 400G" ," 2.9Ghz" ));
105
+ /* ComputerFactory class contains static method getComputer(abstractFactory fac) */
106
+ System . out. print(c);
107
+
108
+ }
89
109
}
110
+ ````
0 commit comments