Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

How normal class is different from Singleton class?
There is a scenario which i was asked by an interviewer.......

How will you convert normal class into a singleton class......!!!!

I have used Singleton Class in my project but i could not find any difference between normal class and singleton.

Could any one help me on this.

Thanks in advance.
Posted

1 solution

The biggest difference (indeed in code terms pretty much the only difference) is that a Singleton class does not have a public constructor: you have to go via the class GetInstance method (or similar) in order to create an instance as the outside world is not allowed to use:
C#
MySingletonClass msc = new MySingletonClass();
It must use
C#
MySingletonClass msc = MySingletonClass.GetInstance();
Which ensures that there is only ever one instance of the class.
 
Share this answer
 
Comments
♥…ЯҠ…♥ 26-Sep-13 2:45am    
Thanks Griff.... this is what I am expecting......
OriginalGriff 26-Sep-13 3:35am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900