sergdort / CleanArchitectureRxSwift

Example of Clean Architecture of iOS app using RxSwift
MIT License
3.91k stars 494 forks source link

Multiple models for Repository in single UseCase. #78

Closed kaungsoe closed 4 years ago

kaungsoe commented 4 years ago

Let's say we want to save PostDetail model also in this PostsUseCase, in that case, how do we satisfy the generic constraint for it.

final class PostsUseCase<Repository>: Domain.PostsUseCase where Repository: AbstractRepository, Repository.T == Post {

    private let repository: Repository

    init(repository: Repository) {
        self.repository = repository
    }

     func save(postDetail: PostDetail) -> Observable<Void> {
        return repository.save(entity: postDetail)
    }

     func save(post: Post) -> Observable<Void> {
        return repository.save(entity: post)
    }

}
sergdort commented 4 years ago

I would make another UseCase. As it does handle a different part of the business logic 🤷‍♂️

kaungsoe commented 4 years ago

No workaround other than creating new usecase?

sergdort commented 4 years ago

I would not call it a workaround, but a good design practice. UseCases (and any classes in general) should be responsible for handling one peace of business logic, hence it will be easy to refactor, test and fix bugs.