design patterns - Android - Couchbase lite - DAO - MyClass extends Document -


i'm working on android application using couchbase lite. should have classes extending com.couchbase.lite.document ?

pros: dao integrated in class.

cons: - every object linked document, if want new object, must create new document in couchbase? - else?

for example:

public class userprofile extends document {      public userprofile (database database, string documentid);      public map<string, object> getproperties();      public boolean ismodified();      public boolean update() throws couchbaseliteexception {         if (ismodified()) {             super.putproperties(getproperties());             return true;         }         else             return false;     } } 

i not recommend extending document. instead, either use maps, or use jackson json library create pojos. create simple helper class wrap database operations (including replication, if you're using that).

off top of head, wouldn't because subclassing doesn't fit of ways retrieve documents, documents heavy-weight objects, , preferred way update takes account possibility of conflicts, more difficult. (see this blog post discussion of last point.)

i've never tried work around these issues in subclassing approach, seems pretty more pain it's worth.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -