4 ms·
getters/setters became popular with RMI. Public fields have all kind of security/code smell issues. Most classes should be immutable.
by xxs 6y ago
getters/setters became popular with RMI. Public fields have all kind of security/code smell issues. Most classes should be immutable.
- JulianMorrison 6y agoPublic writeable fields are threading and encapsulation smells but public read-only fields just say, this data is part of my interface.
- deleted 6y ago[deleted]
- xxs 6y agowell, yes however fields cannot be part of an 'interface' in java. (they can but they'd be static) I do use package private fields liberally, though. Just not non-static public fields.
- JulianMorrison 6y agoInterface as used here means the broader concept of a "a class's interface is its public advertised operations" and not the specific Java thing called an interface.