一些背景:我正在创建一款游戏。在这个游戏中,玩家可以拥有一座房子。房子里可能包含家具对象,而这些家具可能具有自定义的纹理设置。一个家具可能包含不同数量的纹理。一个家具有几个插槽(0-x)用于纹理。
房子类:
家具类:
在玩家房屋家具管理GUI中,将会有类似以下的内容:
房子类:
public class House {
private List<Furniture> furniture;
public House() {
furniture = new ArrayList<Furniture>();
}
public List<Furniture> getFurniture() {
return furniture;
}
public void addFurniture(Furniture furniture) {
furniture.add(furniture);
}
}
家具类:
public class Furniture {
private Map<Integer, Texture> textures;
public Furniture() {
textures = new HashMap<Integer, Texture>();
}
public void setTexture(int index, Texture texture) {
textures.put(index, texture);
}
}
在玩家房屋家具管理GUI中,将会有类似以下的内容:
List<Furniture> furniture = house.getFurniture();
// Let's assume that player selected one piece of furniture which he wants to edit
Furniture furniture = .... // This is the one he selected.
// Later on he chooeses a texture and I set it:
furniture.setTexture(some_index, new Texture(...));
问题
在setTexture方法内更新数据库是否有意义?从数据持有类中与数据存储区交互是否是良好的实践?