In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Creational design patterns are composed of two dominant ideas. One is encapsulating knowledge about which concrete classes the system uses. Another is hiding how instances of these concrete classes are created and combined.
The creational patterns aim to separate a system from how its objects are created, composed, and represented. They increase the system’s flexibility in terms of the what, who, how, and when of object creation.
Consider applying creational patterns when:
A system should be independent of how its objects and products are created.
A set of related objects is designed to be used together.
Hiding the implementations of a class library or product, revealing only their interfaces.
Constructing different representation of independent complex objects.
A class wants its subclass to implement the object it creates.
The class instantiations are specified at run-time.
There must be a single instance and client can access this instance at all times.
Instance should be extensible without being modified.
Related Tags
Tutorials
The builder pattern, as the name implies, is an alternative way to construct complex objects. This pattern should be used when we want to build different immutable objects using the same object-building process. 1. The GoF Builder Pattern Before starting the discussion, I want to make it clear that the builder pattern that we are …
The prototype design pattern is used in scenarios where an application needs to create a number of instances of a class that have almost the same state or differ very little.
Abstract factory is a factory of factories; a factory that groups the individual but related/dependent factories together without specifying their concrete classes.
The factory pattern simply generates an instance for client without exposing its instantiation logic to the client.
To create a singleton, make the constructor private, disable cloning, disable extension and create a static variable to house the instance