CQM-DataCapsuleBreakUp¶
Do not declare non-const data members public
Required inputs: IR
Public data members could be modified by other types in a way that violates the invariants of the class and should be avoided.
Motivation
A basic goal of the object-oriented approach is data encapsulation, i.e., the object-oriented classes function as abstract data types that offer only services that are themselves based on data internal to the class. Through this form of data encapsulation, the class is able to ensure the correctness and validity of the internal data by implementing appropriate checking mechanisms and taking dependencies into account.
Otherwise, invalid objects may exist, whose further processing in the system can lead to consequential errors, the origin of which can then only be found with great additional effort. The clever data encapsulation therefore performs the validity check each time the data is changed. To make this possible, direct uses of the data are no longer allowed.
This rule is based on the CQM Quality Indicator: Datenkapselaufbruch (p. 179-182).
Reference
Simon, Frank/ Seng, Olaf/ Mohaupt, Thomas (2006): Code-Quality-Management: Technische Qualität industrieller Softwaresysteme transparent und vergleichbar gemacht, 1st ed., Heidelberg, Germany: dpunkt.verlag GmbH.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
protected_field |
Protected non-const data member. |
None |
False |
public_field |
Public non-const data member. |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
allow_protected_members¶
allow_protected_members : bool = True
allowed¶
allowed
Specifies allowed fields as pairs (class name pattern, field name pattern).Example: (re.compile('.*'), re.compile('x')) to allow x in all classes.Type: list[typing.Tuple[typing.Union[typing.Pattern[str], typing.Callable[[bauhaus.ir.Node], bool]], typing.Union[typing.Pattern[str], typing.Callable[[bauhaus.ir.Node], bool]]]]
Default:
[]
ignore_const_members¶
ignore_const_members : bool = True
ignore_pod¶
ignore_pod : bool = True
ignore_structs¶
ignore_structs : bool = True
ignore_templates¶
ignore_templates : bool = False