Clean Architecture: Combining Interactors

你说的曾经没有我的故事 提交于 2019-12-08 15:44:06

问题


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:

  1. 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.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!