...
Wiki Markup |
---|
*OBJ00-EX1:* "if a class is package-private or is a {{private}} nested class, there is nothing inherently wrong with exposing its data fieldsâassumingfields—assuming they do an adequate job of describing the abstraction provided by the class. This approach generates less visual clutter than the accessor-method approach, both in the class definition and in the client code that uses it" \[[Bloch 2008|AA. Bibliography#Bloch 08]\]. This exception applies to both mutable and immutable fields. |
...
Wiki Markup |
---|
\[[Bloch 2008|AA. Bibliography#Bloch 08]\] Items 13: Minimize the accessibility of classes and members; 14: In public classes, use accessor methods, not public fields \[[JLS 2006|AA. Bibliography#JLS 06]\] Section 6.6, Access Control \[[Long 2005|AA. Bibliography#Long 05]\] Section 2.2, Public Fields |
...
04. Object Orientation (OBJ)OBJ00-J. Limit extensibility of classes and methods with invariants to trusted subclasses only 04. Object Orientation (OBJ) OBJ02-J. Never conflate immutability of a reference with that of the referenced object