简体   繁体   中英

Is it possible to partially subclass a ParseObject?

The Parse SDK documentation clearly points out how to subclass an object:

// Armor.java
@ParseClassName("Armor")
public class Armor extends ParseObject {
  public String getDisplayName() {
    return getString("displayName");
  }
  public void setDisplayName(String value) {
    put("displayName", value);
  }
}

But what if you only wanted to get/set parts of a parse object? I am storing member information in parse in the ParseUser table. Each user has their name, email address, number of times they've done something with the app, and possibly later on, personal information like billing info, address, etc. I am currently storing storing the user names in a separate SQL database, but would like to be able to store them in the local datastore, if possible. The problem I see, is that since information is not encrypted in the datastore (I can view contents using an SQLite browser), I do not want to store personal info on the device.

If I create a ParseObject called, say "Members", is there a way I can only fetch the Username/ObjectId for each user, and not retrieve/touch the other details?

if this is not possible, I suppose I can still use SQLite, but maintaining two databases is not optimal. I'm thinking something like the following:

 // Member.java
    @ParseClassName("_User")
    public class Member extends ParseObject {
      public String getMemberName() {
        return getString("userName");
      }
      public void setMemberName(String value) {
        put("userName", value);
      }
    }

You could create two separate ParseObject subclasses: "Member" and "User". Each "Member" object has a "User" object associated with it (and possibly vice versa). This allows you the flexibility to just retrieve the list of "User"s if that's all you need.

Of course, nothing is preventing you from only calling the getters for the information you need and ignoring the others. This is another potential solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM