Cicero
07/21/2021, 12:15 PMinterface DumbInterface {
fun one()
fun two()
}
class DumbInterfaceImpl : DumbInterface {
override fun one() {
println("something")
}
override fun two() {
println("else")
}
}
And when I have something like this is acceptable:
interface NetworkErrorManager {
fun handleRegistrationError(statusCode: Int, errorBody: ResponseBody?): ApiException
fun handleResetPasswordError(statusCode: Int, errorBody: ResponseBody?): ApiException
fun handleLoginError(statusCode: Int, errorBody: ResponseBody?): ApiException
fun handleGetUserProfileError(statusCode: Int, errorBody: ResponseBody?): ApiException
fun handleUpdateUserProfileError(statusCode: Int, errorBody: ResponseBody?): ApiException
fun handleResendConfirmationEmailError(statusCode: Int, errorBody: ResponseBody?): ApiException
fun handleRefreshUserTokenError(statusCode: Int, errorBody: ResponseBody?): ApiException
fun handleLogoutError(statusCode: Int, errorBody: ResponseBody?): ApiException
fun handleDeleteUserError(statusCode: Int, errorBody: ResponseBody?): ApiException
}
I've been trying to get people not to use interfaces when they are not being used as interfaces and just class references --
EXAMPLE: class JustDoingSomethingDumb(iNeedThisOtherDumbClass: DumbInterface ) instead of DumbInterfaceImpl
-- and to use interfaces when we have easily recognizable patterns like this above and being receive with poker faces.
When for exanmple, for the last example, I proposed something like:
interface Network{
val statusCode: Int
val errorBody: ResponseBody?
val errorMessage: String
get() = errorBody?.toString() ?: NetworkErrorManagerImpl.UNKNOWN_ERROR_MESSAGE
fun get(): ApiException
}
sealed class NetworkImpl: Network{
data class HandleRegistrationError(
override val statusCode: Int,
override val errorBody: ResponseBody?,
override val errorMessage: String
) :NetworkImpl() {
override fun get(): ApiException {
return when (statusCode) {
403 -> InvalidClient(
statusCode,
errorMessage
)
else -> handleOtherErrors(statusCode, errorMessage)
}
}
}
}
marlonlom
07/21/2021, 10:13 PMCicero
07/22/2021, 8:18 AM