Mid
From PDF
SOLID
Design Patterns & SOLID
What are anti-patterns related to DI and Singleton?
Short answer: Service Locator anti-pattern: Hides dependencies instead of injecting them explicitly. Overusing Singleton: Leads to hidden global state and testing difficulties. Improper Singleton thread safety: Causes race conditions. Injecting concrete implementations: Violates DIP.
Real-world example (ShopNest)
ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png