问题
I've recently stumbled upon Clean Architecture, by Uncle Bob, and I'm curious to know whether Interactors can execute other Interactors.
For example, these are my Interactors as of now: getEmptyAlbums, getOtherAlbums. Both have Callbacks that return with a list of Albums (An ArrayList of an Album model) respectively.
Am I allowed to have an Interactor called getAllAlbums that executes the previous two Interactors within it's run block?
@Override
public void run() {
getEmptyAlbums.execute();
}
void onEmptyAlbumsReceived(ArrayList<Album albums){
getOtherAlbums.execute;
}
void onOtherAlbumsReceived(ArrayList<Album albums){
mMainThread.post(new Runnable() {
callback.onAlbumsReceived(albums);
}
});
回答1:
I have been pondering the same thing and after finding very little on the subject, I have come to the conclusion "Yes" it is probably the best option.
my reasoning as follows:
- Single Responsibility: If you can't aggregate use-cases, then each can't really be single responsibility. Without aggregation, it means domain logic ends up in the presentation layer, defeating the purpose.
- DRY: use cases can be shared, and should be where it makes sense.
To preserve single responsibility, I would consider limiting aggregating use-cases to do only that, i.e. executing those use cases and doing any final transformations.
Given the age of this question, I'd be interested to know which way you went with this and issues you encountered.
来源:https://stackoverflow.com/questions/43803666/clean-architecture-combining-interactors