crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

Difference between Static vs Singleton class
Question Posted on 03 May 2020Home >> DotNet >> C# >> Difference between Static vs Singleton class

Difference between Static vs Singleton class
Below are the most common differences between Static and Singleton class.
Static Class
(1)As from last couple of questions we knows that we cannot create an instance of static class.
(2)When compiler compiles the static class it treats static class as an abstract and sealed class. So we cannot create instance for static
class and nor extend that.
(3)No Instance we can create
(4)We cannot pass the static class as method parameter.
(5)Static class is generally initialized when it is first loaded for the first time and it may lead to potential classloader issues.
(6)These are not possible with a static class. So the Singleton class is more flexible as compared to static classes.
(7)We will not create clone of static class
(8)It is not possible to dispose the static class.
(9)It is not possible to implement DI design Pattern using Ststic class because ststaic class is not interface driven.
(10)Static class does not have any Object pointer, so the scope is at the App Domain level.

Singleton Class
(1)We can only create a single instance of Singleton class and later on we can reuse that singleton instance.
(2)We cann create a instance.
(3)One important aspect is that Singleton class constructor is always marked as private. So for private we cannot create instance from outside the singleton class. It provides either public static property or a public static method whose job is to create the singleton instance only once and then return that singleton instance each and every time when we called that public static property/method from outside the singleton class.
(4)And we can pass singleton instance as a method parameter in c#.
(5)A Singleton class can be initialized lazily or can be loaded automatically by CLR when the program or namespace containing the Singleton class is loaded.
(6)It is possible to implement interfaces, inherit from other classes and allow inheritance with Singleton class.
(7)It is possible to clone the Singleton class object
(8)We can dispose the objects of Singleton Class
(9)We can implement Dependency Injection in Singleton Class.
(10)In Singleton Class a single object across the application lifecycle, so the scope is at the application level.
0
0



.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

Simplest definition of partial classes and its rules?

Definition of Tuple class with some examples?

Define Race Condition in cSharp?

C#.Net Reserve Words

can we inherit private class level variables in c#






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap