Sign in
Log inSign up

help with java data model repository design

Madiba Razak's photo
Madiba Razak
·Jul 31, 2016

the code below is not complete and the actual implementation is quite verbose , so am mostly looking for help with the logic

basically i have json array with dynamic object types, i can pass to recycler view correctly but having trouble persisting since the model is very dynamic, i resulted to use realm to persist , i procede to store each data in relation model base on data type , and null for the object .

json data structure

[
  {
    type: event // or peep  
    ... // corresponding items like title or date ..
  },
  {type:peeps
  ...
  },

  ...
]

am looking if possible a better implementation than the one i have

Implement --

public class Feeds extends RealmObject {

    public String  Type;



}

public class Peeps extends RealmObject {
    public int Id;
    private string owner ;
    //...
}

public class Event extends RealmObject {
    public int Id;
    private String title ;
    //...
}

then on recycler onbindview we get the corresponding data type

Feed.type == event  title ;
titleview.setText ( feed.event.getitle())
Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct