Grokking Modern Mobile System Design Interview
0% completed
Dependency Injection and Testing
Testing becomes easier when a component does not create all of its own dependencies. Dependency injection means providing those dependencies from outside the component.
The idea is simple: give a screen model the services it needs instead of making it construct a database, network client, and clock internally.
Start with constructor injection
An order screen model might accept these dependencies:
OrdersScreenModel(ordersRepository, clock)
The repository provides order data. The clock provides the current time for rules that depend on time.
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%