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

Multiple models for Repository in single UseCase. #78

Closed
kaungsoe opened this issue Mar 30, 2020 · 3 comments
Closed

Multiple models for Repository in single UseCase. #78

kaungsoe opened this issue Mar 30, 2020 · 3 comments

Comments

@kaungsoe
Copy link

kaungsoe commented Mar 30, 2020

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
Copy link
Owner

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

@kaungsoe
Copy link
Author

No workaround other than creating new usecase?

@sergdort
Copy link
Owner

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.

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

2 participants