Skip to content

Avoid Public Attributes in Classes ​

WarningAnti-Patterns & Bad Practices#EC PUBLIC_ATTRRemote Enabled

Overview ​

Avoid mutable public attributes in classes.

ATC Finding Message: Avoid public attributes; use private/protected with getters or READ-ONLY

Rationale ​

Public attributes let any caller read or overwrite internal state, so the class cannot enforce its own invariants. They also expose implementation details that become difficult to change without breaking consumers. Keep state private or protected and expose read-only getters or behavior methods that control access.

Non-Compliant ​

abap
CLASS cl_model DEFINITION PUBLIC CREATE PUBLIC.
  PUBLIC SECTION.
    DATA mv_state TYPE i.
ENDCLASS.

Compliant ​

abap
CLASS cl_model DEFINITION PUBLIC CREATE PUBLIC.
  PUBLIC SECTION.
    METHODS get_state RETURNING VALUE(rv_state) TYPE i.
  PRIVATE SECTION.
    DATA mv_state TYPE i.
ENDCLASS.

Suppression ​

To suppress findings for this rule, append the pseudo-comment to the statement:

abap
" Standard pseudo-comment:
... "#EC PUBLIC_ATTR

" SAP CI_ prefix format:
... "#EC CI_PUBLIC_ATTR

Technical Details ​

Released under the MIT License.