Design Pattern (3-1), Differences between Singleton & Static Class

These will be a series of articles about Design Patterns. We start from the MVC Pattern:

Singleton and Static classes can only have one "copy" available in memory, and both classes can be used to maintain the global state of an application, however, there are many differences between them. This article will briefly discuss the differences.

A static class can be a singleton class

For example, the following VoteMachine class is a static class that acts as a singleton class to register the votes of users.

It will give the correct result in the multi-threaded scenario, as shown below.

Differences between Static class and Singleton class

References


Similar Articles