Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Why we should avoid the singleton anti-pattern at all and replace it with DI in java?

user-image
Question ajoutée par Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
Date de publication: 2014/04/23
Javed Khan
par Javed Khan , Senior Programmer Analyst , Barclays Technology

  • May introduce global state
  • Get tightly coupled to multiple other classes
  • Hide dependencies
  • Can make unit testing classes in isolation difficult

Instead, look into Dependency Injection. Several of the IoC libraries will handle lifetime management for you.

(As always, there are exceptions, such as static math classes and C# extension methods.)

More Questions Like This