samedi 9 janvier 2021

Did Joshua Bloch say not to use singleton with underlying resources?

I have been reading Joshua Bloch's Effective Java book. In item #5, he seems to say not to use a singleton or static utility class to implement a class that depends on one or more underlying resources, and do not have the class create these resources directly, use dependency injection.

I would like some clarification on precisely what advice he is trying to give here. Should I not make a singleton or static utility class at all (and use just a class) when I have some variables that affect that class? Or I can use it, but just need to use dependency injection? Which of these strategies would be most consistent with Bloch's advice?

Aucun commentaire:

Enregistrer un commentaire