Versions Compared

Key

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

...

Code Block
bgColor#ccccff
public class Widget {
  private int total;
  void add (someType someParameter) {
    total++;
    // ...
  }
  void remove (someType someParameter) {
    total--;
    // ...
  }
  public int getTotal () {
    return total;
  }
}

Exceptions

Wiki Markup
*EX1:* According to \[[Conventions 09|AA. Java References#Conventions 09]\]:

One example of appropriate public instance variables is the case where the class is essentially a data structure, with no behavior. In other words, if you would have used a struct instead of a class (if Java supported struct), then it's appropriate to make the class's instance variables public.

Risk Assessment

Failing to declare data members private can break encapsulation.

...