In the previous blog, we have seen about “What is Design Pattern?” Now this is time to explore the types of Design Pattern. Let’s start this with Singleton Design Pattern. Singleton Design pattern belongs to Creational Design Pattern. Singleton Pattern ensures that only one instance of the class exists through out the application life cycle. Singleton design pattern is the best-known pattern in software development. So, if you are following singleton design pattern then you can not create multiple instances of a single class.
Let’s see this by an example:
Create a Console Application and create 4 classes Program.cs, Singleton.cs , Product.cs, Employee.cs
Once you run this application you can see below output screen.
In Product.cs and in Employee.cs we have called functions from Singleton.cs but with only a single instance.
Now there may be a query that why Singleton class is sealed. The answer is sealed class avoids inheritance and so not even nested class can derive Singleton class to allow creating multiple instances. If you like this blog please like us on Facebook:https://www.facebook.com/SharePointCafenet/