Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseCase for each method of repository? #227

Open
mHerasimov opened this issue Mar 14, 2017 · 5 comments
Open

UseCase for each method of repository? #227

mHerasimov opened this issue Mar 14, 2017 · 5 comments

Comments

@mHerasimov
Copy link

mHerasimov commented Mar 14, 2017

Does we need to create UseCases for each method from Repository interface in domain layer?

For example assume that I have such Repository interface

interface ThingRepository {
    void create(Thing thing);
    void delete(Thing thing);
    List<Thing> readAll();
    int size();
}

As you can see there is size() method that returns number of records in database or in file, whatever. And this method is pretty fast.
I guess that there is no need for UseCase for this method because it wouldn't block UI thread and can be executed synchronously.

So could you explain me when you create UseCases and when you don't. Basically is there any rules for UseCase creation?

Sorry if there is some misunderstanding in this issue.

@PhungVanHoa
Copy link

why no one answer ?. i am also interested in this

@mHerasimov
Copy link
Author

mHerasimov commented Apr 3, 2017

ok, let's summarize, I see 2 versions

  1. use Interactor & Presenter & View for simple action
  2. perform call from presentation layer to domain layer directly

use Interactor & Presenter & View
pros

  • you strictly obey principles of Clean

cons

  • too many code to write and maintain
  • big complexity

perform call from presentation layer to domain layer directly
pros

  • easy to implement and maintain

cons

  • calls to domain in Fragment or Activity, that is mixing abstraction and concrete realization

currently I think of creation of interface like this for synchronos simple actions

interface SyncUseCase<T, R> {
    R perform(T t);
}

it will remove direct calls from Activity/Fragment to Repositopy

currently I am not sure which way is right and it'll be good if someone correct me

@mHerasimov
Copy link
Author

mHerasimov commented Apr 3, 2017

@chanhoncongian I'll ask on SO, meaby somebody will answer
here is question

@mHerasimov
Copy link
Author

mHerasimov commented Apr 11, 2017

Hi guys, eventually I came across this issue.
I've read code of various repos related to Clean Architecture including this one. Author of this repo creates interactor for each repository method.
But we can use one presenter for multiple interactors, as author does.
Just take a look at interactors and presenters implementations.
So we should design our presenters, keeping in mind views (Fragment/Activity) for which we are designing them.

@swapii
Copy link

swapii commented Dec 11, 2017

As you can see there is size() method that returns number of records in database or in file, whatever. And this method is pretty fast.

I think we (developers) shouldn't think like this. We don't know how long each repository method would be executing. And there is the answer. Each repository method must be executed asynchronously. We can write UseCase for this or invoke repository method directly but without blocking main thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants