Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

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

user-image
Question added by Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
Date Posted: 2014/04/23
Javed Khan
by 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

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.