Singleton design pattern in c# .net, static class vs singleton class,Thread safe singleton

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

It means that you don't have the overhead of acquiring the lock if the instance is not null. If you were accessing the instance thousands of times this small overload may have a significant affect.

daveclark
Автор

Clear simple example of the Singleton pattern. Appreciated it.
But I felt the Static classes could have been explained better. It didn't quite hit the point wherein you could have said a static method is completely independent of other class variables and just depends on its parameters (or other static members). Basically not dependent on an instance variable. Also if I want to read some common config XML files, I would provide it as a singleton class so that everyone doesn't have to read the same XML file. It is at a "global" or "App level" and doesn't have to be static method read by every user

padmakrishnan
Автор

awsome and useful understanding..thanks Ramna :)

priyankatripathi
Автор

you easily make out me concept of Singleton....

asharnavya
Автор

instead of having two if blocks to check the "instance" for null can't we put the lock statement at the top of if condition?

prakashnayal
Автор

why if (instance == null) twice? why not just put the lock (syncroot) as first statement in Instance() method?

NickKravitz
Автор

Hi, here you have mentione in the ppt that "instance of the object" but how can we create an instance of the object.We can create the instance of a class only..Either you can say the instance of a class or create the object of a class. But Instance of the object is not making any sense..Can you please clarify it??? Thanks

himanshujain
Автор

When you say "Consider a situation of singleton", What exactly is that situation?
Can you give a real time example?

Nandakishore
Автор

I did not get the logic of lazy initilzation in static class. I mean how come it would impact the feature of singleton ? Anyone who got this kindly explain :)

rashmishukla
Автор

only Indian people understood this English

Автор

Content good. But poor English. Was very difficult to understand his English.

hemantjain