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
+14-2Lines changed: 14 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ Factory design pattern is used when we have a super class with multiple sub-clas
72
72
73
73
74
74
Now let's write the test class.
75
-
75
+
76
76
```java
77
77
importcom.factory.FactoryClass ; //The factory class
78
78
importcom.factory.PC; //sub-class
@@ -92,13 +92,25 @@ Factory design pattern is used when we have a super class with multiple sub-clas
92
92
//Now you can see the output in your console.
93
93
}
94
94
```
95
+
This pattern provides some advantages such as :
96
+
* It provides approach to code for the interface rathan than the implementation.
97
+
* It removes the instantiation of the actual implementation classes from client code, making it more robust.
98
+
* It provides abstraction between implementation and client classes through inheritance.
99
+
100
+
As examples of its implementation in JDK we have :
101
+
* java.util.Calendar, ResourceBundle() and NumberFormat getInstance();
102
+
* valueOf() method in wrapper classes like Boolean , Integer etc.
95
103
96
104
# Abstract Factory
97
105
98
106
This is one of the Creational Pattern and almost similar to Factory Pattern except the fact that it's most like
99
107
Factory of factories.
100
-
Source files are in the package `com.abstractFactory`.
108
+
If you're familiar with __factory design pattern in java__, you'll notice that we have a single Factory class that returns the different sub-classes based on the input provided and the factory class uses if-else or switch statement to achieve this.
109
+
Like our factory pattern post, we will use the same super class and sub-classes.
0 commit comments