Does Singleton violate the principle of single responsibility?

In accordance with the principle of single responsibility :

Each class should be responsible for one part of the functionality provided by the software.

Singleton prevents the creation of multiple instances of a class, providing global access to it.

But this functionality has nothing to do with the actual functionality of the class and what it should provide.

Does this mean that the Singleton pattern violates SRP?

+4
source share
1 answer

The short answer is NO for most cases. Again, this may depend on the implementation of Singleton.

, , , . , , . , /.

. . Singleton , , DB. Singleton , .

+5

Source: https://habr.com/ru/post/1611835/


All Articles