Bird
Raised Fist0

Which design pattern or principle best matches the scenario where a client class depends on abstractions and receives its dependencies from an external source at runtime?

easy🔍 Pattern Recognition Q2 of Q15
OOP & Design Patterns - Interface Segregation & Dependency Inversion - Fat Interfaces & IoC
Which design pattern or principle best matches the scenario where a client class depends on abstractions and receives its dependencies from an external source at runtime?
ASingleton pattern
BFactory Method pattern
CDependency Injection via Inversion of Control container
DInterface Segregation Principle
Step-by-Step Solution
Solution:
  1. Step 1: Understand the scenario

    The client depends on abstractions and receives dependencies externally at runtime, which is the hallmark of Dependency Injection (DI) implemented via an IoC container.
  2. Step 2: Analyze options

    Dependency Injection via Inversion of Control container correctly identifies DI with IoC. Factory Method pattern creates objects but does not inject dependencies externally. Singleton pattern controls instance creation but is unrelated to DI. Interface Segregation Principle is about interface design, not dependency provision.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    External provision of dependencies -> DI with IoC [OK]
Quick Trick: External runtime dependency provision -> DI with IoC [OK]
Common Mistakes:
MISTAKES
  • Confusing Factory Method with DI
  • Thinking Singleton manages dependencies
  • Mixing ISP with dependency management
Trap Explanation:
PITFALL
  • Candidates often mistake Factory Method for DI or think Singleton handles dependency injection, missing the IoC concept.
Interviewer Note:
CONTEXT
  • Tests recognition of DI and IoC pattern in dependency management.
Master "Interface Segregation & Dependency Inversion - Fat Interfaces & IoC" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes