Skip to content

Commit d1dffe0

Browse files
authored
Creational Pattern
1 parent 24d64dd commit d1dffe0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Design Patterns in Java
2+
3+
### 1. Creational Patterns:-
4+
- used to solve common problems when creating objects.
5+
- simplify the creation of complex objects.
6+
- Improve overall readability of code.
7+
8+
Types of Creational Patterns:-
9+
10+
i) Builder Pattern:-
11+
When to use:- - when dealing a complex object that requires alot of parameters.
12+
- when trying to prevent mistakes from creating a complex object.
13+
- when trying to avoid unreadable, big constructors that are sometimes required for complex creation.
14+
15+
ii) Factory Pattern:-
16+
Advantages:- - Hides the internal logic of creating objects.
17+
- Enables the programmer to add new different objects of the same type.
18+
Disadvantages:- - The complexity of this pattern tends to be high.
19+
- Cannot be refractored into.
20+
21+
iii) Abstract Factory Pattern:- It contains a super factory which creates object factories.
22+
23+
iv) Singleton Pattern:- - Prevents the instantiation of a class more than once.
24+
- provides single access to an object.
25+
use cases:- logger, thread pool, cache, Report.
26+
27+
v) Prototype Pattern:- It is used whenever object is very expensive to create.
28+
- creating new objects with clone(), not new()
29+
- Makes use of an interface.
30+
- shallow cloning, deep cloning (Shallow cloning copies only instance variables of an object whereas Deep cloning copies the other object references as well)
31+
- objects are still unique even if they are copied.
32+
Disadvantages:- - usually comes with other design patterns.
33+
- Increases complexity for creating a deep copy.
34+
vi) Object Pool Pattern:- The pool will allocate a predefined number of objects and the client will use these objects.
35+
Advantages:- - Objects are cached.
36+
- Enforces objects reusability.
37+
Disadvantages:- - Complexity is high
38+
- Tends to rely on other patterns.
39+
- Low popularity.

0 commit comments

Comments
 (0)