Creational Design Patterns

Design Pattern provides a guideline (best practices) to solve a problem that might occur in software development. These Design Pattern solutions were obtained by various trials and test methods used by a huge number of developers over a very long period of time. In this post, we are going to discuss the creational design patterns as defined by the Gang of Four (GoF).

Design Pattern solutions are independent of any programming language and platform and represent an idea to solve a common problem. If you are new to design patterns, I would highly recommend you to read the “Introduction to Design Patterns” article.

What are Creational Design Patterns

The Creational Design Patterns are concern with the way in which an instance of an object is created. It helps in reducing the complexities and instability by creating the object instances only on a need basis.

The creational design patterns reduce the decoupling created due to the direct use of a “new” operator by an object to instantiate its dependencies. There are are a total of five Creational Design Patterns.

Creational Design Patterns
Creational Design Patterns

Let us discuss the overview of each of these creational patterns and if you want to know more or how to implement the same in C#, please follow the link provided.

Singleton Design Pattern

The Singleton Design Pattern ensures that there is one and only one instance of a class that exists throughout the application runtime. The Singleton class also provides a global access point and so that it can return the only instance it created and serve the same to whoever wants to access it.

Singletuon Creational Design Patterns
Singleton UML

Factory Method Design Pattern

The Factory Pattern is a creational design pattern that defines an interface to instantiate a class but does not specify which implemented class will be instantiated and let the process defer until application runtime. Therefore, this pattern relies on class hierarchy and all the classes must either implement an interface or inherit from an abstract class. This hierarchy abstraction help to hides the object creation logic.

Factory method creational design pattern
Factory Method UML

Abstract Factory Design Pattern

The Abstract Factory Pattern is a creational pattern that defines an interface for creating a family of related objects without specifying their implementation. To explain in simple words Abstract Factory Pattern is a design pattern that returns a factory class instance from a list of factories classes which in turn return the required concrete class instance.

The Abstract Factory Pattern is an extension over the Abstract Method Factory Pattern that represents a single family of instances whereas Abstract Factory represents multiple Factories of related objects.

Creational Design Patterns 1
Abstract Factory UML

Builder Design Pattern

The Builder Pattern is a creational design pattern that is used to build an object in a step by step manner and assembling the output of each step to get the final object instance. The pattern is commonly used to build complex objects.

As per the GoF, the Builder pattern is defined as Separate the construction of a complex object from its representation so that the same construction process can create different representations. In simple words, the Builder pattern describes the process to separate an object from its construction and the same process can be used to create different objects.

Builder creational design pattern
Builder Design Pattern UML

Prototype Design Pattern

The Prototype Design Pattern is used to create a clone or a duplicate of an existing object in order to avoid the expensive operation of new object creation. The pattern is used when object creation is an expensive affair (time-consuming, memory-intensive, or complex to create)

Prototype or cloning of an object is achieved using shallow copy or deep copy of the object state in question to the cloned object. Choosing the copying mechanism can have different behavior of the cloned object

prototype creational design pattern
Prototype Design Pattern UML

This concludes the post about the Creational Design Patterns and I hope you found this post helpful. Thanks for visiting, Cheers!!!

[Further Readings: Builder Design Pattern in C# |  Prototype Design Pattern in C# |  Top 5 Blazor Component Libraries |  Abstract Factory Design Pattern in C# |  Factory Method Pattern in C# |  Singleton Design Pattern in C# |  Introduction to Design Patterns |  Microsoft C# Version History |  Microsoft .NET Core Versions History |  Microsoft .NET Framework Version History |  Introduction to WPF in .NET Core |  Useful Visual Studio 2019 extensions for database projects |  Machine Learning Model Generation |  Important Global Visual Studio 2019 Shortcuts |  Datasets for Machine Learning    ]  

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
oldest
newest most voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x