简体   繁体   English

是否可以部分继承ParseObject?

[英]Is it possible to partially subclass a ParseObject?

The Parse SDK documentation clearly points out how to subclass an object: Parse SDK文档明确指出了如何对对象进行子类化:

// 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. 我在ParseUser表中的解析中存储成员信息。 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. 每个用户都有自己的姓名,电子邮件地址,使用该应用程序完成操作的次数,以及以后可能还会收到诸如帐单信息,地址等个人信息。我目前正在将用户名存储在一个单独的SQL数据库中,但希望能够将它们存储在本地数据存储中。 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. 我看到的问题是,由于信息未在数据存储区中加密(我可以使用SQLite浏览器查看内容),所以我不想在设备上存储个人信息。

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? 如果我创建一个名为“ Members”的ParseObject,是否有一种方法只能获取每个用户的用户名/ ObjectId,而不能检索/触摸其他详细信息?

if this is not possible, I suppose I can still use SQLite, but maintaining two databases is not optimal. 如果这不可能,我想我仍然可以使用SQLite,但是维护两个数据库并不是最佳选择。 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". 您可以创建两个单独的ParseObject子类:“成员”和“用户”。 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. 这是另一个潜在的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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