Skip to content

Commit 9337494

Browse files
committed
Fulfilling more explanations
1 parent 004401f commit 9337494

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,21 @@ We'll implement the thread safe one here. Classes are in the package `com.single
5858
}
5959
}
6060
```
61-
# Pattern Factory
61+
### Pattern Factory
6262

63-
Factory Pattern is one of the Creational Design pattern and it's widely used in JDK as well as frameworks like
64-
Spring and Struts.
65-
This pattern is used when we have a super class with multiple sub-classes and based on the input, we need to return one of the sub-class.
63+
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.
6664

65+
* Super Class
66+
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.
67+
see `com.factory`.
68+
* sub-classes
69+
Let’s say we have two sub-classes PC and Server with implementation in `com.factory`
70+
71+
Here's what we have in image :
72+
73+
74+
Now let's write the test class.
75+
6776
```java
6877
import com.factory.FactoryClass ; //The factory class
6978
import com.factory.PC; //sub-class

0 commit comments

Comments
 (0)