ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
تاريخ النشر: 2014/04/23
Javed Khan
من قبل 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.)

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟