Complete the code to declare a repository interface in Kotlin.
interface UserRepository {
fun getUserById(id: Int): [1]
}The repository interface defines a method to get a User object by its ID.
Complete the code to implement the repository interface with a local data source.
class LocalUserRepository : UserRepository { override fun getUserById(id: Int): [1] { // fetch user from local database return User(id, "Name") } }
The implementation returns a User object as defined in the interface.
Fix the error in the repository method signature to make it suspendable for coroutine support.
interface UserRepository {
suspend fun getUserById(id: Int): [1]
}The suspend function must return the User type to support asynchronous fetching.
Fill both blanks to create a repository method that fetches users from a remote source and returns a list.
interface UserRepository {
suspend fun getAllUsers(): [1]<[2]>
}The method returns a list of User objects fetched asynchronously.
Fill all three blanks to implement a repository method that saves a user and returns a success flag.
interface UserRepository {
suspend fun saveUser(user: [1]): [2]
}
class UserRepositoryImpl : UserRepository {
override suspend fun saveUser(user: [3]): Boolean {
// save user logic
return true
}
}The saveUser method takes a User object and returns a Boolean indicating success.