Hello, i am trying to design a basic API module fo...
# android
m
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
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
cool, thanks for the direction
q
If I am not wrong coroutines as of now in experimental ,
d
@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
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
@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
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…