Marko Novakovic
01/16/2022, 3:15 PMUseCase
, for example, or anything else that has common structure and needs input and output parameters:
1. having UseCase
interface like this:
fun interface UseCase<Parameters, Result> : suspend (Parameters) -> Result
class SomeUseCase : UseCase<String, Int> {
override suspend fun invoke(parameter: String): Int = parameter.toInt()
}
2. extending function for every instance:
class SomeUseCase : suspend (String) -> Int {
override suspend fun invoke(parameter: String): Int = parameter.toInt()
}
2nd approach allows for passing multiple parameters instead of just one
with 1st approach we need to group parameters inside an data class
and unpack then when we need them which makes sense because those are cohesive information for given UseCase
am open for ideas/suggestions