假设您有一个想要共享/同步相同模型/对象的客户端和服务器。模型相互指向,并且您希望它们在客户端和服务器之间发送/序列化后继续指向同一个对象。我目前的解决方案大致如下:
class Person {
static Map<Integer,Person> allPeople;
int myDogId;
static Person getPerson(int key){
return allPeople.get(key);
}
Dog getMyDog() {
return Dog.getDog(myDogId);
}
}
class Dog {
static Map<Integer,Dog> allDogs;
int myOwnersId;
static Dog getDog(int key) {
return allDogs.get(key);
}
Person getMyOwner() {
return Person.getPerson(myOwnersId);
}
}
但我对这个解决方案不太满意,字段是整数之类的。这也应该是一个很常见的问题。所以我在这里寻找的是这个问题的名称、模式、通用解决方案或库/框架。