Filip Husnjak
05/13/2018, 10:01 AMpublic interface Callback {
void onSuccess(Class item);
void onError(Error error);
}
I was thinking of replacing this callback with a closure instead and my question is if it is better to add two closure parameters or to just have one? Is there a best practice for this?
Ex:
onSuccess: (item: Class) -> Unit, onError: (error: Error) -> Unit
OR
callback: (item: Class, error: Error) -> Unit
/Thanksorangy
sealed
hierarchy and single lambda with a Result
parameter, or even a DSL builder for complex cases. Mostly it depends on how often do you use this event source: if it’s only couple of places, choose whatever is simpler. If it’s public facing API and/or there are many places you subscribe to the event then you might want to invest a little into usability.Filip Husnjak
05/13/2018, 10:09 AM