MISRA Discussion Forums
Rule 11-0-1 and protected members - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.11 Member access control (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=140)
+---- Thread: Rule 11-0-1 and protected members (/showthread.php?tid=1355)



Rule 11-0-1 and protected members - tw39124 - 03-07-2017

Rule 11-0-1 says that "Member data in non-POD class types shall be private" and the example clarifies that both "public" and "protected" members violate this rule. The rationale says "the implementation retains more control over how the object state can be modified".

I fail to see how protected members diminish the "control" over the object state that the implementation has. Can someone explain in more detail why protected member variables specifically are disallowed? A subtype has an "is-a" relationship with the base type, after all, so I don't see why it shouldn't benefit from inheriting the base type's member variables.


Re: Rule 11-0-1 and protected members - misra cpp - 12-07-2017

It encourages strong partitioning and data hiding.

We will consider adding an exception for abstract classes in the next version