OOP.APPF
Avoid "public" or package-private instance fields
Description
This rule flags any "public" or package-private instance field.
Instance fields are an implementation detail of your class. It is good practice to hide such implementation details from users of your class. Instead of making these fields "public" or package-private, provide the user with methods to access and/or change these fields.
Example
package OOP;
class APPF {
int a = 10; // Violation
private int c = 14;
}
Repair
Declare the field "private" and provide access methods to the field if needed.
Reference
Haggar, Peter. Practical Java - Programming Language Guide. Addison Wesley, 2000, pp.170 - 173.
|