Wednesday, January 11, 2017

Difference Static Class and Singleton Pattern

1. You can not create instance of static class while you can create instance of singleton class.

2. Static class loaded by compiler when the program or namespace containing the class is loaded.
While singleton can be lazy load when needed. Static class are always loaded.

3. Static class can not have instance constructor while singleton class can have instance constructor.

4. Static class not pass in a function while singleton object can be pass in a function.

5. Static class can not inherit another static class while singleton class can inherit another class.

6. Static class should have all method static while singleton class can have both methods.

7. Static class is fast in comparison of singleton.

8. Static class can not implement interface while singleton class can implement interfaces.

No comments: