Sobes.tech
Junior — Middle

Which of the five SOLID principles can be violated when using the Singleton pattern?

sobes.tech AI

Answer from AI

Using the Singleton pattern most often violates the Single Responsibility Principle (SRP) from SOLID.

Singleton combines two responsibilities: managing its single instance and executing the main business logic. This complicates maintenance and testing, as the class is responsible for both creation and functionality.

Additionally, Singleton can indirectly affect the Open/Closed Principle, as changing the way the instance is created requires modifying the class itself.

Which of the five SOLID principles can be violated… - sobes.tech