Tuesday, November 11, 2008

Visibility of Accessors

/**
Visibility of Accessors
*/

Always strive to make them protected, so that subclasses can access the fields. Only when an 'outside class' needs to access a field should you make the corresponding getter or setter public. Note that it is common that the getter member function be public and the setter protected.

No comments: