Closed
Description
This is not an issue.
It's really a clearly defined architecture. A lot of technologies are introduced into the architecture, I 've never used them before, Dagger, RxAndroid, Butternife, etc.
But I am little confused by the fine defined UseCases, for example , GetUserList, GetUserDetails for user usecases. If I want to do user search, I must define SearchUser usecase, I want to do CRUD for many many Objects, I need to write hands of usecases separately.
And, I'm not sure how to pass parameters to the usecases. For example, GetUserDetails, pass the userId by constructor in UserModule. How can I pass a search critera to SearchUser UseCase? A Map? Or a Model? Is there another way instead of constructor?
Thank you very much for any suggestion.
Activity
spirosoik commentedon Oct 8, 2015
Of course you can but you must use a few tools to make your life easier.
johnwatsondev commentedon Oct 8, 2015
@sitexa I have solved this problem. Here is a NOT elegant enough solution.
No callback function. Just pass your criteria through Varargs.
LoginPresenter.java
UseCase.java
UserLoginCase.java
UserRepository.java
UserDataRepository.java
UserDataStore.java
CloudUserDataStore.java
RestApi.java
RestApi.java
Please @me if you have any issue. Thanks.
sitexa commentedon Oct 9, 2015
Thank you very much, @johnwatsondev .
It is a good approach I'd like to follow, but I don't know how to write the 'OperatorSynchronousUnsubscribe' class, would you please give that to me ?
Thanks.
sitexa commentedon Oct 9, 2015
@spirosoik , I am glad to have your words.
But my life is not easy if you don't tell me what those tools are and what they can do work for me.
Thank you.
spirosoik commentedon Oct 9, 2015
@sitexa on of this example you will see that the data layer uses files. You can use ORMLite for database. Also for the API you can use Retrofit in order to get back Observables as a response.
johnwatsondev commentedon Oct 9, 2015
@sitexa It a approach that prevent memory leak. But it has a weakness as konmik said below.

Reference:
ReactiveX/RxJava#3148
OperatorSynchronousUnsubscribe
There is a more elegant solution for preventing memory leak in Android. (Recommend)
https://github.com/trello/RxLifecycle
spirosoik commentedon Oct 9, 2015
@johnwatsondev cool thanks for the info.
sitexa commentedon Oct 9, 2015
@johnwatsondev , it seems too difficult for me to get the point from the posts you referred. I need do some research on that topic.
sitexa commentedon Oct 9, 2015
@spirosoik , thank you for your reply.
I do use OkHttp/Retrofit in the network layer under the data layer. My point is should I write many many usecases separately for each object, like CRUD.
johnwatsondev commentedon Oct 10, 2015
@sitexa I have used this architecture in real project.
As you said I have write some
UseCase
to do business stuff at the beginning. Eg:UserLoginCase
,UserRegisterCase
,UserSendVerifyCodeCase
,UserForgetPasswordCase
etc.But i found they are belong to User Module.
So i created a
UseCaseList
which extendsUseCase
. Here is the SNAPSHOT:Then My
UserUseCaseList
can extendUseCaseList
and overridebuildUseCaseObservable
method.We can package some similar
UseCase
or in same Business Module together in my opinion. My code is just a simple idea.I have realized that code is not elegant. It can be replace with Queue or other Data Structure. Maybe you could give me some refactor suggestion.
You can argue with me by email or QQ (503548433).
Thanks in advance!
sitexa commentedon Oct 10, 2015
@johnwatsondev , added your QQ.
alexandru-calinoiu commentedon Oct 12, 2015
@johnwatsondev what is QQ?
johnwatsondev commentedon Oct 13, 2015
@alexandru-calinoiu Sorry about that.
QQ is a chinese IM software.