【发布时间】:2020-02-24 08:38:31
【问题描述】:
我正在使用房间数据库进行本地缓存。在我的实体中,我有其他对象,它们的 getter 具有与其用途相关的接口的返回类型。但是房间找不到字段的吸气剂。我的目标是将这些接口用作返回类型,以便我可以将来自多个远程源的数据添加到一个数组中。如何在实现灵活和良好抽象的同时做到这一点?
public interface Venue {
Location getLocation();
Contact getContact();
}
public interface Location {
double getLongitude();
double getLatitude();
}
public interface Contact {
String getPhoneNumber();
String getFacebookUsername();
}
public class VenueSourceOne implements Venue{
private VenueSourceOneLocation venueSourceOneLocation;
private VenueSourceOneContact venueSourceOneContact;
Location getLocation(){
return venueSourceOneLocation;
}
Contact getContact(){
return venueSourceOneContact
}
}
public class VenueSourceTwo implements Venue{
private VenueSourceTwoLocation venueSourceTwoLocation;
private VenueSourceTwoContact venueSourceTwoContact;
Location getLocation(){
return venueSourceTwoLocation;
}
Contact getContact(){
return venueSourceTwoContact
}
}
public class Main{
....add to a List<Venue> and do something on the UI
}
【问题讨论】:
标签: android android-room