Posts

Showing posts with the label C# | Singleton Design Pattern | Creational Design Pattern

C# | Singleton Design Pattern | Creational Design Pattern

Singleton pattern is one of the simplest design patterns in C#. 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. - The Singleton pattern is a design pattern that restrict the instantiation he lifetime of the application, the instance remains same. - Throughout the lifetime of the application the instance will remain same. - Instance should be requested instead of created, if instance not available then create the instance, then provide otherwise provide available instance.  Why we need Singleton design pattern? - When there is single resource throughout the application. e.g- Database, Log File etc. - When there is a single resource and the...