我们正在开发的一个项目,需要一个轻量级和一个重量级的同一个实体类的对象。我们有一个简单的解决方案,但需要从专家的角度了解是否有更好的解决方案。我们的解决方案如下:
public interface User{
//Some variables and methods
}
public class LightWeightUser implements User{
//Lightweight code goes here
}
public class HeavyWeightUser implements User{
//HeavyWeight code goes here
}
我们计划在数据库处理部分使用 hibernate。
最佳答案
这是一种可能的选择:
public class User {
//Light-weight code goes here.
}
public class HeavyWeightUser extends User {
// Heavy-weight code goes here.
}
关于java - 同一对象的重量级和轻量级版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4882507/