+ 2
Why singleton is blamed more than celebrated
Hi I am aware that singleton design pattern is useful in few scenarios like database connection , application logger as well as global application settings. However, It is singleton which gets criticized more than it is celebrated. Below are some key points for its criticism: 1. Breaks Single responsibility ---> How ? Can you please share more insights? 2. Breaks testability ----> Why it hinders to test singleton?
1 Respuesta
+ 1
Sure:
---
1. Breaks SRP:
Singleton handles both instance control and business logic — two responsibilities.
2. Hurts Testability:
Hard to mock, creates hidden dependencies, and can cause shared state between tests.
---
Use with care; DI is usually better.