I’m a computer science student at a university working on an independent study. As I’m just learning, I’m trying to make sure I get the basics down, to develop good habits for the future.
Recently I had taken to enforcing encapsulation as much as possible. For example, using Collections.unmodifiableList() to return unmodifiable lists. For my study I’m using Ebean for my database model and have found that, 1) every class must have a public no arg constructor and 2) public getters and setters for every field. I understand that the way Ebean works, using reflection, requires this, it just makes me wonder: Is encapsulation that important?
Ebean does not require any public constructors/getters/setters. The constructor can be private and you can make Ebean use fields directly.
See chapter 14 of the user guide.
Both Hibernate and myBatis(though not an ORM) can handle private constructors/fields, too.