Creational Design Patterns are mostly concerned with the manner involved with creating class instances. These are further characterized as class-creation and object-creation Patterns. The object creation or instantiation is done implicitly using design patterns rather than directly. Thus, for a use-case, there is flexibility involved with the object creation.
Underlying Patterns of Creational Design Patterns
Patterns under this category, provide a way to construct objects when constructors will not serve your purpose. Creation logic of objects is hiding. The program based on these patterns are more flexible to deciding objects creation according to your demand and your use cases of the application. There are following listed design patterns come into this category.
- Factory Pattern
- Abstract Factory Pattern
- Singleton Pattern
- Prototype Pattern
- Builder Pattern
Spring 5 Design Pattern Book
Creational design patterns are associated with the way of creation of the objects. Creation logic of the object is hiding to the caller of this object.
As traditionally, we all are aware how to create the using new keyword in java as below:
Account account = new Account();
But this way is not suitable for sometime, because it is hard coded way to create an object, also it is not a best practice to create an object if object might be changed according to the nature of the program. Here creation design pattern provide the flexibility to create an according to the nature of program.
Types of Creational Design Patterns
There are following types of Creational Design Patterns.
Abstract Factory Pattern
In this pattern, a factory of related objects is created by an interface without specification of the class name. The factory passes the objects by following the Factory Pattern.
Builder Pattern
This pattern is used for a stage by stage creation of a complex object by combining simple objects. The final object creation depends on the stages of the creative process but is independent of other objects.
Factory Method Pattern
This pattern is employed mostly during development in Java. It provides implicit object instantiation through common interfaces.
Object Pool Pattern
Object pooling is used to reduce object creation cost when it is high for certain process and thus improves performance. It employs the method of object caching and simply retrieves objects from the cache pool instead of having to create it. The number of objects in the pool can be restricted to keep from continual growth.
Prototype Pattern
In Prototype patterns, object duplication is performed while performance is monitored. A prototype interface pattern is present to produce a copy of an object. It is used to restrict memory/database operations by keeping modification to a minimum using object copies.
Singleton Pattern
This pattern involves the present of one class and restricting object creation to a single object. The presence of a single object removes the need for object instantiation for accessing.
Let’s see the these design patterns in details in the next articles.
Happy Learning with us!!!