...
This compliant solution declares total
as private
and provides a public
accessor so that the required member can be accessed beyond the current package. The add()
and remove()
methods modify its value without violating any class invariants.
Note that accessor functions methods should be careful about providing references to private mutable objects; see rule "OBJ05-J. Defensively copy private mutable class members before returning their references" for details.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e7c922e7d8d9ac92-d982b040-4248498f-b618888f-375833b9e959d2ef54219716"><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="a200fe29fd4950d0-00955ac9-41d4442f-97f8b50d-b8bc5063e473bbbc04c6d45e"><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="3125ec0513062c62-4a4df07d-47d54496-b4509c0f-6bc4ebbeda7ae0699153d82f"><ac:plain-text-body><![CDATA[ | [[Long 2005 | AA. Bibliography#Long 05]] | §2.2, Public Fields | ]]></ac:plain-text-body></ac:structured-macro> |
...