java - Is it appropriate to update database from a javabean class? -


a little bit of context: creating of game. in game player can own house. house may contain furniture objects, , furniture may have custom textures set. 1 piece of furniture may contain different amounts of textures. piece of furniture has several slots(0 - x) textures.

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

the 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 player house furniture management gui there this:

list<furniture> furniture = house.getfurniture(); // let's assume player selected 1 piece of furniture wants edit furniture furniture = .... // 1 selected. // later on chooeses texture , set it: furniture.settexture(some_index, new texture(...)); 

the question

would make sense update database inside settexture method? practice interact datastore within data holding class?

in experience, it's not practice make update directly in these java beans. should use dao pattern. in way, can abstract crud operation on model.

for more detailed information, should visit dao pattern


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -