...
Exceptions
Wiki Markup |
---|
*OBJ01-EX1EX0:* According to Sun's Code Conventions document \[[Conventions 2009|AA. Bibliography#Conventions 09]\]: |
One example of appropriate
public
instance variables is the case where the class is essentially a data structure, with no behavior. In other words, if you would have used astruct
instead of a class (if Java supportedstruct
), then it's appropriate to make the class' instance variablespublic
.
Wiki Markup |
---|
*OBJ01-EX2EX1:* "If a class is package-private or is a {{private}} nested class, there is nothing inherently wrong with exposing its data fields — 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. |
OBJ01-EX3EX2: Static final fields that contain mathematical constants may be declared public.
...
C++ Secure Coding Standard | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="dd4b7aa654499927-865d0241-4377423c-8f5abb76-634a87adc8e7334ee9003052"><ac:plain-text-body><![CDATA[ | [[SCG 2007 | AA. Bibliography#SCG 07]] | Guideline 3-2: "Define wrapper methods around modifiable internal state" | ]]></ac:plain-text-body></ac:structured-macro> |
CWE-766 "Critical Variable Declared Public" |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="eb0c24e26bd80ed4-ca75457e-49504e3c-ba74ac58-d472b8a2a3473f57791f5355"><ac:plain-text-body><![CDATA[ | [[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 | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f966ec97d080e5ef-d4583bc7-4c674e6f-91318b99-beb8b55a33d4baa96fdc4fbc"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [§6.6 "Access Control" | http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="afad8e67116f5b17-6b44d680-48ef4ca5-819aa610-00bdb8153c10c9400378c7bd"><ac:plain-text-body><![CDATA[ | [[Long 2005 | AA. Bibliography#Long 05]] | §2.2, Public Fields | ]]></ac:plain-text-body></ac:structured-macro> |
...