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-ONLYAvoid 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 Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
CHECK_PUBLIC_ATTR | Boolean | true | Report public data attributes in classes (encapsulation violation) |
CHECK_INTF_DATA | Boolean | true | Report 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_ATTRRelated Rules
- Avoid Purely Static Utility Classes —
#EC NO_STATIC_CLS - Prefer Interface Segregation (Small, Focused Interfaces) —
#EC PREF_INTF_SEGREG - Avoid IS INSTANCE OF and CASE TYPE OF Type Tests —
#EC NO_INSTANCE_OF
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_EXPOSED_DATA - Implementation File: zcl_skylint_no_exposed_data.clas.abap