Creating repositories
In this section, we will look at what a repository is and the role it plays in the data layer of an application, and how we can create repositories with various data sources.
The repository represents an abstraction for the data than an application uses, and it is responsible for managing and centralizing the data from one or multiple data sources.
In the previous chapter, we defined the following entity:
data class User( val id: String, val firstName: String, val lastName: String, val email: String ) { fun getFullName() = "$firstName $lastName" }
Here we have a simple User
data class with a few relevant fields. The repository abstraction for the User
data is as follows:
interface UserRepository { fun getUser(id: String): Flow<User> }
Here we have an interface named UserRepository
that...