Conversation
|
||
package com.karumi.rosie.repositorynew; | ||
|
||
public interface Keyable<K> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davideme suggest us the usage of Hashable
as class name and getId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After 2 hours talking about this ;) We've decided that this interface is not needed and we can use hashCode
and equals
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And 30 mins later we've remembered why Cacheable
interface was needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed IRL, the goal of K getKey(); is to be able to cache results of a getAll and be accesible for the method getById.
@Serchinastico After a first review the only points I think we should review are:
I'm going to continue reading the PR, but these are the most important details we should review. IMHO the approach is quite good like to continue with the development. |
|
@Serchinastico This implementation is similar to mine in iOS so except the remarks from @pedrovgs everything seems fine ;) |
I don't know if it's out of scope of this pull request, but I like have a T implementation of the datasources for Memory and for realm and have in other proyect, but we don't need to create that kind of data source every time. Here we have a memory implementation on the sample, but we can move it out to other proyect and reuse for any kind of T data, and make extendible for add new user interfaces. |
I have updated the PR with all your requests, including:
|
values = getPaginatedValuesFromReadables(offset, limit); | ||
} | ||
|
||
if (values != null && policies.contains(ReadPolicy.POPULATE_CACHE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can ReadPolicy.POPULATE_CACHE
be used without any other policy?. As far as I read we should not create a USE_READABLE_POPULATE_CACHE
because if we do that we should also add another policies with the same meaning. Maybe could be enough just checking the policies set contains at least another politcy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you are saying, basically CACHE_POLICY & READ_POLICY are two different things and some combinations doesn't make any sense. We can hide it in another class and let only the values that are correct visible. I'll think about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can create an issue to implement this in the future if you want ;)
Awesome code @Serchinastico review my comments and you already have my 👍 |
Why don't merge this PR and #17 |
I reviewed this PR but I didn't put my 👍 sorry |
Review library visibility
New repositories approach
This is my repositories approach, it doesn't bring anything new to the table, it's just a clean up and a better segregation of interfaces, to wrap up:
Repository
As in the old implementation, if you want to create your repositories just extend from this class. To configure your data sources, call
addReadables
,addWriteables
,addCaches
in your constructor:To do special stuff, like reading only from cache, reading only fresh data, etc, there is a method with a
ReadPolicy
that let's you define those special cases.Readable, Writeable, Cache
This is the separation of the previous
DataSource
interface.Readable
hasget
andgetAll
methods,Writeable
hasaddOrUpdate
,addOrUpdateAll
,delete
anddeleteAll
methods. Finally,Cache
just merges these two interfaces. There is still the problem of having to implement methods you might not need (I might only need to implementget
and don't need to implementgetAll
). You can use one of theEmptyReadable
,EmptyWriteable
andEmptyCache
classes which provides an empty implementation for every method.I did an MVP with an implementation based on annotations where data sources only need to annotate it's
get
method with a@Get
annotation. If the annotation is not present then the repository goes to the following data source. I've done some profiling and the annotation-based implementation is 20 times slower, we are talking about repository calls of 7ms which I think it's not acceptable. We might useapt
but it will take us longer.Pagination is solved in the same fashion as in the previous implementation.
Let me know the parts you like, the parts you don't, and let's close the repositories.