|This rule is Obsolete|
|Synopsis:||Only declare public or protected accessors for data members that must be accessible|
According to [INT#002], no public or protected data may be declared in a class but data members always are to be declared private. Often for this type of data (attributes) accessors are declared. These are trivial methods used to get or set the corresponding data member. When these accessors in turn are public or protected, the data member is just as visible as it would be when being declared public or protected right away. This, together with the fact that methods offered by a class are to be based on a functional requirement leads to the following rules:
- The implementation of a class may directly use (the private declared) data members. It is not required to define private accessors. If however the declaration of the data member is assumed to change in future implementations, it is recommended to declare private accessors for these data members, in which case not even the class implementation directly manipulates the data members.
- When protected or public accessors are declared, one needs to make sure these accessors are based on a functional requirement and not just on the fact that it is easy to access the private data. These accessors, like all member functions,
must preserve the class' invariant.