OOP.AIC
An inner "class" should only be used if it is going to associate with and be visible to the class that contains it
Description
This rule flags any inner class that is not "private".
The inner classes automatically have access to their containing classes' member fields.Therefore, problems can arise if an inner class is not a "private" class.
Example
package OOP;
class AIC {
int getSize () {
return _size;
}
class Inner {
void setSize(int size) {
_size = size;
}
}
private int _size;
}
Repair
class AIC {
int getSize () {
return _size;
}
private class Inner {
void setSize(int size) {
_size = size;
}
}
private int _size;
}
Reference
Warren, Nigel, and Bishop, Philip. Java in Practice . Addison-Wesley, 1999, pp. 10-11.
|