Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a40fa79

Browse files
committed
Abstract Factory Refactoring ...
1 parent 9337494 commit a40fa79

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

‎README.md‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Factory design pattern is used when we have a super class with multiple sub-clas
7272

7373

7474
Now let's write the test class.
75-
75+
7676
```java
7777
import com.factory.FactoryClass ; //The factory class
7878
import com.factory.PC; //sub-class
@@ -92,13 +92,25 @@ Factory design pattern is used when we have a super class with multiple sub-clas
9292
//Now you can see the output in your console.
9393
}
9494
```
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.
95103

96104
# Abstract Factory
97105

98106
This is one of the Creational Pattern and almost similar to Factory Pattern except the fact that it's most like
99107
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.
101110

111+
Codes are available in `com.abstractFactory`.
112+
Here's the implementation of the test class:
113+
102114
```java
103115

104116
public class abstractFactoryTest{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /