0

Differences between static class and singleton class

So basically i understand that both Singleton class and static class can be instantiated once . Is there any other disparity between these 2 concepts?

9th Jan 2017, 6:03 PM
Alex Soh Chye Wat
Alex Soh Chye Wat - avatar
4 Réponses
+ 1
A static class should be not initated because you can access them without having an Instance of them. On the other hand a Singleton class has a method that only allows to instantiate the class once.
9th Jan 2017, 6:14 PM
Andreas K
Andreas K - avatar
+ 1
@AKC Ya, i agree with you. The only purpose of using static constructor in a static class should be for initializing its static members, i think?
9th Jan 2017, 6:39 PM
Alex Soh Chye Wat
Alex Soh Chye Wat - avatar
0
@AKC Is it not that the static class contains a static constrcutor that only get instsntisted once by the CLR during the first reference? So can i say that the implementation of Singleton class is a non-static class since it is instantisted using non-static constrcutor?
9th Jan 2017, 6:29 PM
Alex Soh Chye Wat
Alex Soh Chye Wat - avatar
0
should be fine. But I do not see a purpose for Instantiating a static class, do you, @Alex?
9th Jan 2017, 6:32 PM
Andreas K
Andreas K - avatar