encapsulation

encapsulation is providing public getters/setter access to private variables. in these mehtods one can throw exceptions in case the value being set is invalid.

but if i need access to database within such methods - will it be a best practice?

Comments

  • edited November -1
    Entity objects within transactions can do this for you. See ORM tools and JPA 2.0.
  • Actually connecting to database in this entity will be not the best practice. You should separate your entity and DB stuff, like modern ORMs do - with proxying classes. But be sure that you really need this, because this won't be easy to implement.