Breaker ACT
03/11/2022, 3:59 PMKotlin syntaxI am reading sample Clean Architecture code of Fernando Cejas. He implement as the images, how you think about this approach ? The pros: We can invoke the interface/abstract class which has been injected like a function call Ref
Adam Powell
03/11/2022, 4:10 PMAdam Powell
03/11/2022, 4:13 PMrun
implementations, one of which will crash the app probably unexpectedly, misuses the IO dispatcher and its associated thread pool...Breaker ACT
03/11/2022, 4:15 PMAdam Powell
03/11/2022, 4:24 PMBreaker ACT
03/11/2022, 4:26 PMAdam Powell
03/11/2022, 4:30 PMResult
type of this form, but it's primarily used for infrastructure code that has to manage things like resuming coroutine continuations with either a returned result or a thrown exception. Thrown exceptions still feature heavily there.Adam Powell
03/11/2022, 4:31 PMEither
here, you end up reinventing a lot of language features for error handling and propagation. "railway-oriented programming" is the term to search for thisAdam Powell
03/11/2022, 4:37 PMrun
or onResult
in the images above, where does that exception go? what opportunities are afforded to the developer to handle them? The use of an Either
type implies a single error propagation path that is not thrown exceptions, but meeting that expectation involves yet more consideration and boilerplate that is not present in this exampleAdam Powell
03/11/2022, 4:37 PMBreaker ACT
03/11/2022, 4:43 PMAdam Powell
03/11/2022, 4:48 PMBreaker ACT
03/11/2022, 4:58 PMsealed class AuthResource<out T> {
data class Failure(val error: AuthError) : AuthResource<Nothing>()
data class Success<T>(val result: T) : AuthResource<T>()
}
But when we need to chaining multiple usecase (interactor) call we have to check the type of result so much.
When using Either, we can use the operator flatMap to call the next usecase if previous is success result.
Any idea for my wonder ?Breaker ACT
03/11/2022, 5:00 PMval result1 = authUseCase1.execute()
if(result1 is AuthResource.Success) {
val result2 = someUseCase.execute()
if(result2 is Result.Success) {
.. . . . . .
}
}
Adam Powell
03/11/2022, 5:01 PMBreaker ACT
03/11/2022, 5:04 PMAdam Powell
03/11/2022, 5:05 PMBreaker ACT
03/11/2022, 5:10 PMAdam Powell
03/11/2022, 5:30 PMBreaker ACT
03/11/2022, 5:37 PM