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

Making use cases generic doesn't work with associatedtypes #77

Open
jbehrens94 opened this issue Mar 25, 2020 · 0 comments
Open

Making use cases generic doesn't work with associatedtypes #77

jbehrens94 opened this issue Mar 25, 2020 · 0 comments

Comments

@jbehrens94
Copy link

Hi! Thanks for providing a really nice starting point to think about how to build up an app and separate concerns. Of course, my first improvement was to have a UsecaseProviding and UsecaseDefinable protocol.

public protocol UsecaseProviding {
    associatedtype Usecase: UsecaseDefinable

    func makeUsecase() -> Usecase
}
public protocol UsecaseDefinable {
    associatedtype DomainEntity

    func entities() -> Observable<[DomainEntity]>
    func save(entity: DomainEntity) -> Observable<Void>
    func delete(entity: DomainEntity) -> Observable<Void>
}

However, as soon as I begin the implementation in the Database target, for example:

public final class PostsUsecaseProvider: UsecaseProviding {
    public typealias Usecase = PostsUsecase<Repository<Post>>
}

I'll get an error like: type alias cannot be declared public, because its underlying type uses an internal type because the Repository types are all internal. As they should be. That's specific logic for the database. However, I do want to have a concrete implementation of the Usecase and UsecaseProvider in the Database target.

The easiest fix would be to just publicize the Repository parts, but that feels kind of dirty. How would you fix this?

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

1 participant