There is enum
public enum HQuery { GET_USER_BY_LOG_PASS("select u from User u where u.login = :login and u.password = :password"); public String value; HQuery(final String value) { this.value = value; } } If I refer to the value value in this way: GET_USER_BY_LOG_PASS.value will this violate the principle of encapsulation? Or does enum not apply this rule as rigidly as classes?
enumis a crutch and does not belong to OOP in any way. You should not use it the same way you use objects. encapsulation is not about access to fields, but about knowledge of implementation. the user of the object should not be aware of how this object is arranged inside. he should know the interface and that's it. - Mikhail Vaysmanenumpresented is a bad design and I would not do that. - Mikhail Vaysman