Minimize the accessibility of classes and members

The single most important factor that distinguishes a well-designed module a poorly designed one is the degree to which the modules hides its internal dara and implementation details. A well-designed module hides all of its implementation details, cleanly separating its API from its implementation.

Information hiding doesn’t cause on itself good performance, it enables effective performance tuning.

Information hiding increases software reuses because modules that aren’t tightly coupled often prove useful in other contexts besides the ones for which they were developed.

Information hiding decreases the risk in building large systems, because individual modules may prove successful even if the system does not.

The rule of thumb is simple: make each class or member as inaccessible as possible.

Instance fields should never be public. If an instance field is non-final, or is a final reference to a mutable object, then by making the field public, you give up the ability to limit the values that can be stored in the field. Classes with public mutable fields are not thread-safe.

It is wrong for a class to have a public static final array field, or an accessor that returns such a field.

//potential security hole
public static final Thing[] VALUES = {...}

Faci un comentariu sau dai un răspuns?

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

Acest site folosește Akismet pentru a reduce spamul. Află cum sunt procesate datele comentariilor tale.