Design pattern:
Design pattern represents a industrial best practice that is used by experienced developer. Design pattern concept is needed to develop a framework or understand the framework coding.
Type:
- Creational Patterns: Discuss about a object create by hiding object creation logic.
- Structural Patterns: Structural patterns are concerned with how classes and objects are composed to form larger structures.
- Behavioral Patterns: These design patterns are specifically concerned with communication between objects.
Design Pattern - Factory Pattern (EASY)
A normal factory produces goods; a software factory produces objects. And not just that — it does so without specifying the exact class of the object to be created. To accomplish this, objects are created by calling a factory method instead of calling a constructor.Usually, object creation in Java takes place like so:
SomeClass someClassObject = new SomeClass();
The problem with the above approach is that the code using the SomeClass’s object, suddenly now becomes dependent on the concrete implementation of SomeClass. There’s nothing wrong with using new to create objects but it comes with the baggage of tightly coupling our code to the concrete implementation class, which can occasionally be problematic.
Ref: https://medium.com/educative/the-7-most-important-software-design-patterns-d60e546afb0e
Design Pattern - Abstract Factory Pattern (EASY)
Abstract Factory patterns work around a super-factory which creates other factories. This factory is also called as factory of factories.
Ref: https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm
Design Pattern - Singleton Pattern
Singleton pattern is one of the simplest design patterns in Java. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to create an object.
This pattern involves a single class which is responsible to create an object while making sure that only single object gets created. This class provides a way to access its only object which can be accessed directly without need to instantiate the object of the class.
Implementation Example: Database connection. Connection will be created only one time.
REf: https://www.tutorialspoint.com/design_pattern/singleton_pattern.htm
Design Patterns - Builder Pattern
As the name implies, a builder pattern is used to build objects. Sometimes, the objects we create can be complex, made up of several sub-objects or require an elaborate construction process. The exercise of creating complex types can be simplified by using the builder pattern. A composite or an aggregate object is what a builder generally builds.
When you need multiple object to create a object. That time this design pattern need.
Ref: https://medium.com/educative/the-7-most-important-software-design-patterns-d60e546afb0e