https://github.com/devrezaur/java-design-patterns
https://github.com/devrezaur/java-design-patterns
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/devrezaur/java-design-patterns
- Owner: DevRezaur
- Created: 2023-09-15T05:16:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-30T16:21:35.000Z (over 2 years ago)
- Last Synced: 2025-01-18T13:45:37.230Z (over 1 year ago)
- Language: Java
- Size: 273 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Design Patterns in Java
Design patterns are design level solutions for recurring problems that are commonly faced in the software engineering
domain. In short, design patterns are well-described solution to common software problems.
Using design pattern is considered good practice. As the design of the solution is quite tried and tested, resulting in
higher readability of the final code.
There are about 26 design patterns currently discovered. All of them can be categorised mainly in 3 categories.
* **Creational Pattern**: These patterns are designed for class instantiation. They can be either class-creation
patterns or object creational patterns.
* **Structural Pattern**: These patterns are designed with regard to a class's structure and composition. The main goal
of most of these patterns is to increase the functionality of the classes involved, without changing much of its
composition.
* **Behavioural Pattern**: These patterns are designed depending on how one class communicates with others.

# Creational Pattern
### Singleton Pattern
The Singleton Design Pattern is a creational pattern, whose objective is to create only one instance of a class and to
provide only one global access point to that object. These are the characteristics of singleton pattern:
* Private constructor
* Ensures only one object creation of a particular class
* Has two variation. Lazy initialization and eager initialization
* Thread safe
### Prototype Pattern
Prototype Pattern says that cloning of an existing object instead of creating new one and can also be customized as per
the requirement.
This pattern should be followed, if the cost of creating a new object is expensive and resource intensive. These are
the characteristics of prototype pattern:
* Used when the cost of creating an object is expensive or complicated
* It hides complexities of creating objects
* Should be used when you want to keep the number of classes in an application minimum