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
+13-4Lines changed: 13 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -58,12 +58,21 @@ We'll implement the thread safe one here. Classes are in the package `com.single
58
58
}
59
59
}
60
60
```
61
-
# Pattern Factory
61
+
###Pattern Factory
62
62
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.
66
64
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
+
67
76
```java
68
77
importcom.factory.FactoryClass ; //The factory class
0 commit comments