Avoid Purely Static Utility Classes
WarningAnti-Patterns & Bad Practices#EC STATIC_CLSRemote Enabled
Overview
Avoid static-only classes; use instantiable classes.
ATC Finding Message:
Avoid static-only classes; declare instance methods and interfaces
Rationale
A class made only of static methods cannot be mocked through an interface, so every caller is tightly coupled to the implementation. Static state also leaks between tests and makes behavior order-dependent. Inject an instance through an interface and use instance methods instead.
Non-Compliant
abap
CLASS cl_math_util DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
CLASS-METHODS add IMPORTING a TYPE i b TYPE i RETURNING VALUE(r) TYPE i.
CLASS-METHODS sub IMPORTING a TYPE i b TYPE i RETURNING VALUE(r) TYPE i.
ENDCLASS.Compliant
abap
CLASS cl_math_util DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_math_util.
ENDCLASS.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC STATIC_CLS
" SAP CI_ prefix format:
... "#EC CI_STATIC_CLSTechnical Details
- Native ATC Class:
ZCL_SKYLINT_NO_STATIC_CLS - Implementation File: zcl_skylint_no_static_cls.clas.abap