Is it appropriate to update the database from the javabean class?

A bit of context: I'm creating a game. In this game, a player can own a house. A house can contain furniture, and custom textures can be installed on this furniture. One piece of furniture may contain a different number of textures. A piece of furniture has several slots (0 - x) for textures.

House Class:

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);
      }
}

Furniture class:

 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);
       }
 }

In the game interface for managing furniture in the house there will be something like this:

List<Furniture> furniture = house.getFurniture();
// Let 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(...));

Question

Does it make sense to update my database from the setTexture method? Is interacting with a data warehouse from a data storage class a good practice?

+4
source share
1 answer

, java beans. DAO. , CRUD .

DAO

+1

All Articles