Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For any given body of code, we can compute the minimum accessibility for each class and member that avoids introducing new compilation errors. The limitation is that the result of this computation may lack any resemblance to what the designer intended when the code was written. For example, unused members can obviously be declared to be private. However, such members could be unused only because the particular body of code examined coincidentally lacks references to the members. Nevertheless, this computation can provide a useful starting point for a programmer who wishes to minimize the accessibility of classes and their members.

Related Guidelines

Bibliography

[Bloch 2008]

Item 13, "Minimize the Accessibility of Classes and Members"
Item 16, "Prefer Interfaces to Abstract Classes"

[Campione 1996]

Access Control

[JLS 2011]

§6.6, "Access Control"

[McGraw 1999]

Chapter 3, "Java Language Security Constructs"

...