|Synopsis:||Declare non-constant data members private|
As a consequence when data needs to be accessed, be it by a derived class or an external class, protected or public Set and Get methods (Accessors) need to be implemented for these private data members. This way, the class implementation is separated from the class interface.
Note that declaring data members protected is usually a design error, and easily becomes a maintenance problem. See the convincing justification in section 220.127.116.11 of [Stroustrup]. If you want to model a data structure, with public access to its data members, then use a struct type.
Exception: constant data members are often used as constant values with no need of information hiding. In this case it's allowed to declare these members public or protected.
|Ellemtel Rule 22|
|ISC++ Rule 10.1|