midOOP

What is Dependency Injection in OOP?

Updated May 17, 2026

Short answer

Dependency Injection provides objects their dependencies instead of creating them internally.

Deep explanation

It decouples object creation from usage, improving testability and flexibility in system architecture.

Real-world example

Injecting database service into API controllers.

Common mistakes

  • Using 'new' inside business logic classes.

Follow-up questions

  • What are DI types?
  • Why is DI important?

More OOP interview questions

View all →