Avoid FRIENDS in class definitions
WarningAnti-Patterns & Bad Practices#EC FRIENDSRemote Enabled
Overview
Avoid FRIENDS in class definitions.
ATC Finding Message:
Avoid FRIENDS; expose behavior via public methods
Rationale
FRIENDS exposes private and protected members to another class and creates a hidden bidirectional dependency. It defeats encapsulation and makes both classes harder to change independently. Expose a public method or interface instead of granting friendship.
Non-Compliant
abap
CLASS lcl_service DEFINITION PUBLIC FINAL FRIENDS lcl_helper CREATE PUBLIC.
PUBLIC SECTION.
METHODS execute.
ENDCLASS.Compliant
abap
CLASS lcl_service DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
METHODS execute.
ENDCLASS.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC FRIENDS
" SAP CI_ prefix format:
... "#EC CI_FRIENDSTechnical Details
- Native ATC Class:
ZCL_SKYLINT_NO_FRIENDS - Implementation File: zcl_skylint_no_friends.clas.abap