Skip to content

Instantly share code, notes, and snippets.

@DenisBronx
Created August 23, 2022 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DenisBronx/d92b991c253d3b9f1187b9ec0facf9a5 to your computer and use it in GitHub Desktop.
Save DenisBronx/d92b991c253d3b9f1187b9ec0facf9a5 to your computer and use it in GitHub Desktop.
Avoid Use Case Boilerplate Approach 2
data class SomeModel(val id: String, val name: String)
interface SomeModelRepository {
suspend fun getSomeModels(): Answer<List<SomeModel>, String>
}
interface GetSomeModelUseCase {
suspend operator fun invoke(): Answer<List<SomeModel>, String>
}
class GetSomeModelUseCaseImpl(
private val someModelRepository: SomeModelRepository
) : GetSomeModelUseCase {
override suspend fun invoke() = someModelRepository.getSomeModels()
}
class SomeViewModel(private val getSomeModelUseCase: GetSomeModelUseCase) : ViewModel() {
fun load() {
viewModelScope.launch {
val result = getSomeModelUseCase()
// Do something with the result
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment