It is difficult to control how data members declared public
or protected
are accessed. Attackers can manipulate such members in unexpected ways. Therefore data members must be declared private
. Use wrapper accessor methods to expose class members that are beyond the package in which their class is declared. Using wrapper methods enables appropriate monitoring and control of the modification of data members (for example, by defensive copying, validating input, and logging). The wrapper methods can preserve class invariants.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f2830521d699e502-901fc885-4d1345b2-b79c93db-528a2209f6f55896f0550c53"><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="ff330c66df54d731-e4f7cc19-4eeb472a-bd099bcf-8dd2cebc48e303df09e5cbe7"><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="3a85d4a7ab172bf8-5c20b253-4b024a13-9c1ba99c-a126232e471a0dbfd3abe9bc"><ac:plain-text-body><![CDATA[ | [[Long 2005 | AA. Bibliography#Long 05]] | §2.2, Public Fields | ]]></ac:plain-text-body></ac:structured-macro> |
...