Android清洁架构:存储库模式问题

时间:2018-01-02 20:19:31

标签: android kotlin repository-pattern

我目前正在开发一款Android应用,尝试遵循Clean Architecture指南。该应用程序检索最新的新闻标题,并让用户自定义他们的新闻源。在我的域层中,我有以下存储库接口:

interface ArticleRepository {
    fun getTopArticles(request: TopArticleRequest): Single<List<Article>>
    fun getRecentArticles(request: RecentArticleRequest): Single<List<Article>>
}

现在我想让用户自定义新闻Feed,所以我创建了UserInfoRepository

interface UserInfoRepository {
    // Feed customization settings. 
    fun getSubscribedNewsSources(): Single<List<NewsSource>>
    fun subscribeToNewsSource(sourceId: String) // Pass ID or object?
    fun unsubscribeFromNewsSource(sourceId: String) // Pass ID or object?

    // Should this repository contain the following methods or 
    // should they belong to the ArticleRepository?
    fun getBookmarkedNewsArticles(): Single<List<Article>> 
    fun bookmarkNewsArticle(articleId: String) // Pass ID or article?
}

由于用户可以保存文章以供日后阅读,因此存储库包含为文章添加书签和检索已添加书签的文章的方法。但是,我不确定应该在哪里放置管理书签文章的方法。一方面,加书签的文章是用户特定的东西。另一方面,这些方法在Article模型上运行,这使我认为这些方法应该属于ArticleRepository

所以我的问题:这些方法最好属于UserInfoRepository还是ArticleRepository?我可以使用通常存储库管理某个实体/模型类型的经验法则吗?

0 个答案:

没有答案
相关问题