TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  INT#002Checked automatically with code checker

Synopsis:Declare non-constant data members private
Severity Level:2
Category:Class Interface


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 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.

Literature References:
Ellemtel Rule 22
ISC++ Rule 10.1