https://kotlinlang.org logo
#android
Title
# android
m

maplonki

02/14/2018, 1:23 AM
Hello, i am trying to design a basic API module for an android app, i’m having issues trying to design the class relation (trying to use generics) Its there any guide or resource i can use for best practices when doing this kind of stuff? Thanks in advance
d

dave08

02/14/2018, 3:44 AM
Use specific return values (one data class, or a sealed class) and a function for each request w/ all params you need for that request (you can also use retrofit interface and it'll implement them for you...), transform the response into that return value class so that your business logic doesn't have to understand your api contract but rather more businesss logic terminology. Use dependency injection (like #dagger , #kodein or #koin) for mock or real dependency resolution, don't hard code them in. You can look into #coroutines or #rx to avoid async tasks for the requests... Yhere's probably lots of projects on github that could guide you... good luck!
👍 1
m

maplonki

02/14/2018, 4:12 AM
cool, thanks for the direction
q

quock

02/14/2018, 6:23 AM
If I am not wrong coroutines as of now in experimental ,
d

dave08

02/14/2018, 6:54 AM
@quock They're already being used in production by many, JB said that they are production ready if you followed #coroutines this has been asked many many times. We're also using them in production with no problems...
👍 1
r

rkeazor

02/14/2018, 1:18 PM
Dependency Injection isn’t for mocking dependencies , its for providing them. You could use a Isolation Framework(like Mockito) to handle to mocking class, rather than doing it manually
d

dave08

02/14/2018, 1:21 PM
@rkeazor For functional tests (especially instrumentation...), it's probably better to create mock classes... or when there's a more complex hierarchy, fixture classes... then the DI could be used to inject those instead of the real deps...
r

rkeazor

02/14/2018, 1:25 PM
lol thats what i just said
Isolation Frameworks create mock classes lol. thats what they do. Mockito, powermock ,ect….
@maplonki as for as class relations, this can only be achieve if there is a common super…