UseCase

abstract class UseCase<ReturnType, Params>

Base class for every use case (GetScreenUseCase, SendNetworkRequestUseCase, the data-source ones, etc.) — a single-method, Result-returning unit of domain logic, always run on Dispatchers.IO via invoke rather than the caller's own dispatcher.

Parameters

ReturnType

the type this use case produces on success.

Params

the input this use case needs — a dedicated Params data class by convention when more than one value is needed, Unit when none is.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
abstract suspend fun execute(params: Params): Result<ReturnType>

The use case's real logic — implement this, never call it directly (call invoke instead, which adds the Dispatchers.IO dispatch).

Link copied to clipboard
suspend operator fun invoke(params: Params): Result<ReturnType>

Runs execute on Dispatchers.IO — the only sanctioned way to run a UseCase.

Link copied to clipboard

UseCase.invoke overload for a use case whose Params is Unit — lets a parameterless use case be called as useCase() instead of useCase(Unit).