Montreal Y
Montreal Y

Reputation: 1

Clean architecture interactor implementation

I'm trying to separate each layer with Android Clean Arch. I follow the project from https://github.com/dmilicic/Android-Clean-Boilerplate, and Uncle-Bob's article/code. For now, I didn't use RxJava, Dragger, etc. just dbflow orm database. Don't want make a mess now.

There are several data repositories' interface in domain for storage implementation. For each kind of data, there are several methods like insert/add, delete, update, getXXXByXX etc. In the example code, it's just User or Cost repository, and for each data, eg. User has three files(implementation) in interactor.

interactor: DefaultSubscriber GetUserDetails GetUserList UseCase

repository: UserRepository

Suppose there are User, Cost, Device such three repositories, and in interactor there will be 3X4--12 methods files. If there's way to reduce files and make one repository's methods into one Impl file like UserOps which involves methods? Or any other recommendation.

Upvotes: 0

Views: 884

Answers (1)

jam01
jam01

Reputation: 132

I'd recommend you read up on Aggregates.

Basically you should only have Repositories for objects that are considered aggregates. An aggregate is an object that can always stand alone and make sense, it contains one or more objects. In your case, even with not a lot of information, I'd say that you have 2 aggregates: user, and device. User is a thing that always makes sense and doesn't need device or cost to make sense. Cost on the other hand doesn't make sense without the thing that it is a cost for, therefore the aggregate would be device which has a cost. In practice this means that you have 2 Repositories, one for retrieving users and one for retrieving devices which come wirh costs.

Again, since there's not a lot of information it could very well be that in your application devices don't make sense without a user so your aggregate would just be user and when you add/retrieve one you get a user that has devices that have a cost. Or all objects could make sense on their own in which case you would have 3 Repositories but I doubt that's the case.

Upvotes: 1

Related Questions