Singleton Design Pattern explained in Hindi (हिंदी) with code example C# | Design Patterns Series
ฝัง
- เผยแพร่เมื่อ 28 ก.ย. 2024
- In this video, we will discuss about the singleton design pattern. What is the problem it solves, the code structure of the pattern and code example of using this pattern.
Recommended readings:
Clean Architecture: A Craftsman's Guide to Software Structure and Design : amzn.to/3VLJaXc
Design Patterns: Elements of Reusable Object-Oriented Software: amzn.to/3B4zr4P
Head First Design Patterns: amzn.to/3B4ZTLJ
Singleton is a creational design pattern, which ensures that only one object of its kind exists and provides a single point of access to it for any other code.
Topics covered:
Introduction to Singleton design pattern
Problem statement
Solution provided
Code Structure
C# Code example
Lazy implementation
Double checked locking
#designpatterns #cleancode
---------------------------------------------------------------------------------------------
My setup:
Mic: amzn.to/44HGe1H
Laptop: amzn.to/3pclzTe
Keyboard: amzn.to/3B3e3Nn
Mouse: amzn.to/3VLKB82
GreaT explaination
Nice and clear concept explanation thanks
Excellent
Thanks
It's showing error when I apply lock
What is the error message?
Mostly interviews asked this ...on how you can make single pattern thread safe !!! BTW very nice ...God bless you
very nice explain
Thank you.
Great Explanation You have solved my Headache
Great explanation, Do you have video on Factory Patter as well ?
th-cam.com/video/I2DbKwKHeUA/w-d-xo.html
Thank you so much for making video on pattern could you pls make on all patterns
th-cam.com/play/PLmzGdRRZtjPfkKJroG4fHSKquN5AIpHw3.html
nice
thanks Sir, Very well explained
Thanks for the great explanation Sir !! . However, I have a question on lock mechanism . Suppose there are two threads trying to create singleton instance then how is the lock deciding which thread should go first?
It is a very rare condition for 2 threads to try to acquire a lock at exactly same time but in that case there can be internal thread priorities which can be used. In any case, lock will prevent the threads to execute the code at same time.
Thanks for the reply sir 👍
Great knowledge i appreciate you 🤗
Very comprehensively described !
Dose it require to make class as Sealed?
It's not mandatory but if you don't make it sealed then someone can create a child class and create multiple objects of the child class. Sealed class will prevent the inheritance.
Is it the same way we create singleton class ?
Yes, using singleton pattern and creating a Singleton class is same thing.
Can you made tutorial on blazor with entity framework