Dependency Injection
Loose coupling pattern
Interview Relevant: Software design
Dependency Injection
Pass dependencies to objects rather than creating them inside.
Code Examples
python
1class Service:
2 def __init__(self, db_connection):
3 self.db = db_connection # Injected dependency
4
5# Usage
6db = Database()
7service = Service(db)