I am working on refactoring java code base to Kotlin. As you can see below code, it include duplicated params declaration in both class constructor
and subscribeToPush
function. Suppose class take more than one lambda and each include few params, it would be really messy with duplication. Any improvement i could make to avoid this situation
//suppose subscription method 4 params
class PushNotificationStrategy (val subscription: (context: Context, token: String, ......) -> Observable<CommonChatSubscription>) {
//Again I have to declare 4 params with types and name here again
fun subscribeToPush(context: Context, token: String, .....): Observable<CommonChatSubscription> {
return subscription(context, token, ......)
}
// On and Off strategies
companion object {
val On = PushNotificationStrategy({ context, token ->
val apiPushSubscription = ApiPushSubscription(context)
apiPushSubscription.subscribePushService(token)
.onErrorReturn {
Timber.e(it, "Push subscription failed with %s", it.message)
CommonChatSubscription()
}
})
val Off = PushNotificationStrategy({ context, token ->
Observable.just(null)
})
}
}