Android-CleanArchitecture
Android-CleanArchitecture copied to clipboard
Type-level parameter description
As per the latest revision of the repo, dynamic parameters became a Parameters generic that was defined as a simple inner data class, like such UseCase<User, GetUserDetails.Params>
For the sake of furthering the discussion past pragmatism into exploration territory, what if the dynamic dependencies were also part of the Params type as such -using Kotlin 1.1- :
// Generic
interface Params
interface Params0 : Params
interface Params1<T>: Params {
val first: T
}
interface Params2<T, U>: Params {
val first: T
val second: U
}
...
interface UseCase<T, in P: Params> {
fun buildUseCaseObservable(params: P): Observable<T>
}
// In the domain
typealias UserId = Int
typealias UserInfo = Params1<UserId>
class GetUserDetails: UseCase<User, UserInfo>
See that none of these requires an implementation to be defined, and that no new inner classes are required to be able to use only names related to the domain. It also tells the GetUserDetails
class user at first glance what the class dependencies are, and that they're checked at compile time too.
As for the implementation, ParamsX could easily use any data class or Tuple-like construct.