๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

Programming Concepts Intermediate

What is Dependency Injection?

A design pattern where objects receive their dependencies from external sources rather than creating them internally.

Dependency injection (DI) passes dependencies to a class instead of having the class create them. Instead of class UserService { db = new Database() }, you write class UserService { constructor(db) }. This makes code testable, flexible, and loosely coupled.

Types include constructor injection, setter injection, and interface injection. DI containers (Spring, Angular's injector) automate dependency resolution. DI is fundamental to testable code - mocking dependencies becomes trivial.

Related Terms

Hash Table
A data structure that maps keys to values using a hash function, providing average O(1) time complexity for lookups, insertions, and deletions.
Technical Debt
The implied cost of additional rework caused by choosing a quick solution now instead of a better approach that would take longer.
Composition over Inheritance
A design principle favoring object composition (has-a relationships) over class inheritance (is-a relationships) for code reuse.
Event-Driven Architecture
A software design pattern where components communicate by producing and consuming events rather than direct method calls.
SOLID Principles
Five design principles for writing maintainable, flexible object-oriented code: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.
Version Control
A system that records changes to files over time, allowing you to recall specific versions, collaborate, and track history.
View All Programming Concepts Terms โ†’