What is it
Acts as a middle layer between rest of your application and data access logic
Split by Service and Repository
- Service: contains all the logic
- Repository: handles all data
Interacting with API requires a service class
- Service class injects the repository to interact with the data
After fetching the data from the repository, the data is consumed in the service class
- You inject the repository class into the constructor of the service
- This repository class implementation can be changed/swapped as long as the typed interface is the same
- The repository class can have completely different underlying implementation, but it won't break how the service has been implemented