Skip to content

Avoid Exposed Mutable Data in Classes and Interfaces ​

WarningAnti-Patterns & Bad Practices#EC PUBLIC_ATTRRemote Enabled

Overview ​

Avoid mutable data in public classes and interfaces.

ATC Finding Messages:

  • Avoid public attributes; use private/protected with getters or READ-ONLY
  • Avoid mutable DATA in interfaces; declare CONSTANTS or move to class

Rationale ​

Public mutable attributes in classes and DATA declarations in interfaces breach object-oriented encapsulation by allowing external callers to directly mutate internal state without invariant validation. Exposing state leaks implementation details and prevents clean contract evolution. Restrict data to PRIVATE/PROTECTED sections with getters (or READ-ONLY), and keep interfaces strictly stateless with methods and CONSTANTS.

Non-Compliant ​

abap
CLASS cl_model DEFINITION PUBLIC.
  PUBLIC SECTION.
    DATA mv_state TYPE i.
ENDCLASS.
INTERFACE if_customer.
  DATA mv_balance TYPE i.
ENDINTERFACE.

Compliant ​

abap
CLASS cl_model DEFINITION PUBLIC.
  PUBLIC SECTION.
    DATA mv_state TYPE i READ-ONLY.
ENDCLASS.
INTERFACE if_customer.
  CONSTANTS c_default_status TYPE i VALUE 1.
  METHODS get_balance RETURNING VALUE(rv_balance) TYPE i.
ENDINTERFACE.

Configuration & Thresholds ​

This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:

Parameter NameData TypeDefault ValueDescription & Guidance
CHECK_PUBLIC_ATTRBooleantrueReport public data attributes in classes (encapsulation violation)
CHECK_INTF_DATABooleantrueReport data variable declarations inside interfaces (should contain only types, constants, methods)

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.