After studying a couple of blog posts on the topic, I got confused as there were different implementations by different developers but they have all used single interface for repository.
Assume, we have following interface for repository
interface Repository<T> {
fun get(): List<T>
fun save(items: List<T>)
}
For a specific implementation of this repository with T = Users
, Repository.get()
, downloads some data from sever and cache it.
For another type of object, say Bundles
I not only need these methods but some additional methods e.g. querying local database for specific column.
In that case, I can't understand, do I need to create a separate interface or add methods to existing single interface, in which case what should I do with the implementation of new methods in other repositories which do not need these methods? It it must to have same interface for all repositories. Personally, I think, its ok to create multiple interfaces for different repositories as long as I abstract them nicely.