Skip to content

Commit c58a742

Browse files
authored
Update README.md
1 parent 8b2da9a commit c58a742

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ __Java Design Patterns__ are divived into tree parts : *Creational*, *Structural
2828
* Prototype Pattern
2929

3030
### Pattern Singleton
31+
32+
Pattern Singleton: > One Class, one Instance.
3133

32-
Pattern Singleton: > One Class, one Instance.
3334
Singleton is one of the Gangs of Four Design patterns and comes in the Creational Design Pattern category.
3435
Singleton pattern restricts the instantiation of a class and ensures that only one instance of the class exists in the java virtual machine. The singleton class must provide a global access point to get the instance of the class. Singleton pattern is used for logging, driver objects, caching and thread pool. Singleton design pattern is also used in other design patterns like __Abstract Factory__, __Builder__, __Prototype__, __Facade__ etc. Singleton design pattern is used in core java classes also, for example __java.lang.Runtime__ , __java.awt.Desktop__.
3536

@@ -64,14 +65,14 @@ We'll implement the thread safe one here. Classes are in the package `com.single
6465

6566
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.
6667

67-
* Super Class
68-
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.
68+
* Super Class : 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.
6969
see `com.factory`.
70-
* sub-classes
71-
Let’s say we have two sub-classes PC and Server with implementation in `com.factory`
72-
Here's what we have in image :
70+
* sub-classes: Let’s say we have two sub-classes PC and Server with implementation in `com.factory`
71+
72+
Here's what we have in image :
7373
[](http://zupimages.net/up/17/13/7w9z.png)
74-
Now let's write the test class.
74+
75+
Now let's write the test class.
7576

7677
```java
7778
import com.factory.FactoryClass ; //The factory class
@@ -99,18 +100,16 @@ This pattern provides some advantages such as :
99100
* It provides abstraction between implementation and client classes through inheritance.
100101

101102
As examples of its implementation in JDK we have :
102-
* java.util.Calendar, ResourceBundle() and NumberFormat getInstance();
103-
* valueOf() method in wrapper classes like Boolean , Integer etc.
103+
104+
* *java.util.Calendar*, *ResourceBundle()* and *NumberFormat getInstance()*;
105+
* *valueOf()* method in wrapper classes like Boolean , Integer etc.
104106

105107
### Abstract Factory
106108

107109
This is one of the Creational Pattern and almost similar to Factory Pattern except the fact that it's most like
108-
Factory of factories.
109-
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.
110-
Like our factory pattern post, we will use the same super class and sub-classes.
111-
110+
Factory of factories. 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. Like our factory pattern post, we will use the same super class and sub-classes.
112111
Codes are available in `com.abstractFactory`.
113-
Here's the implementation of the test class:
112+
Here's the implementation of the test class:
114113

115114
```java
116115

@@ -125,7 +124,6 @@ Factory of factories.
125124
}
126125
```
127126

128-
129127
### Pattern Builder
130128

131129
Builder pattern is a creational design pattern as Factory Pattern and Abstract Factory Pattern. This pattern was introduced to solve some of the problems with Factory and Abstract Factory patterns when the Object contains a lot of attributes. This pattern deals with a static nested class and then copy all the arguments from the outer class to the Builder class.

0 commit comments

Comments
 (0)