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

allow_protected_members

allow_protected_members : bool = True

Whether protected fields should be ignored.
 

allowed

allowed

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: []

Specifies allowed fields as pairs (class name pattern, field name pattern).Example: (re.compile('.*'), re.compile('x')) to allow x in all classes.
 

ignore_const_members

ignore_const_members : bool = True

Whether public const fields should be ignored.
 

ignore_pod

ignore_pod : bool = True

Whether public fields in POD classes should be ignored.
 

ignore_structs

ignore_structs : bool = True

Whether public fields in structs should be ignored.
 

ignore_templates

ignore_templates : bool = False

Whether public fields in generic templates should be ignored.