DEV Community

Discussion on: Generic Singletons

Collapse
 
andreasjakof profile image
Andreas Jakof

Since I read the "Clean Code", I understand you better now.

Well, DI has it's own flaws (some errors only occure during runtime, which would have been compile time errors), but I am getting used to it and you could check for these errors in a separate unit test.

I still don't mind singletones, but you should not use static classes or objects you only get from a static class. Use Factories instead or DI, which handles the singleton problem for you.

I still like generics, though...

Collapse
 
thebuzzsaw profile image
Kelly Brown

Currently, the only true singletons I put up with are classes that are completely immutable with no configuration options or side effects. Even then, I'm hesitant to lock them down, but sometimes I am OK with hiding the constructor and exposing an Instance simply because creating new ones literally just wastes memory.