Dependency injection (DI) hija pattern fejn l-oġġetti jirċievu d-dipendenzi tagħhom minn barra minflok li jkunux jinqalgħu - u dan itejjeb it-testabilità, il-manutenzjoni, u l-flessibilità. Fl-Android, Hilt (mibnija fuq Dagger) hija l-framework DI rakkomandata.
X'inhu DI u għaliex
WITHOUT DI: a class CREATES its own dependencies (tightly coupled, hard to test/change):
class UserRepo { val api = ApiService() } // creates its own dependency — rigid
WITH DI: dependencies are PROVIDED from outside (injected):
class UserRepo(val api: ApiService) // receives it → flexible, testable
→ Benefits: TESTABILITY (inject mocks/fakes in tests), DECOUPLING, easier to swap
implementations, centralized dependency management, less boilerplate (with a framework).
