Skip to content

Commit 0b0e9b2

Browse files
committed
Implementing abstract factory
1 parent 8de49a4 commit 0b0e9b2

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Java Designs Pattern
1+
# Java Design Patterns
22

33
Here's is an implementation of some Design Patterns from scratch :p
44

@@ -44,8 +44,7 @@ Pattern Singleton: One Class, one Instance.
4444
There are many implementations of this pattern, but we will implement the Thread Safe one.
4545
Classes are in the package `com.Singleton`;
4646

47-
```java
48-
47+
```java
4948
import com.singleton.SingletonThreadSafe;
5049

5150
public class SingletonTest {
@@ -63,7 +62,8 @@ Classes are in the package `com.Singleton`;
6362
//Now check out your console.... What the hell, the two instances have the same reference :o
6463
}
6564
}
66-
```
65+
```
66+
6767
# Pattern Factory
6868
6969
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
8686
Computer comp2 = fc.getComputer("Server",30,900,9);
8787
System.out.println(comp2);
8888
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+
}
89109
}
110+
````

0 commit comments

Comments
 (0)