Declare Constructor in PUBLIC SECTION
WarningClean ABAP & Modern Syntax#EC PREF_PUB_CTORRemote Enabled
Overview
Declare Constructor in PUBLIC SECTION.
ATC Finding Message:
Declare constructor in PUBLIC SECTION, even if class is CREATE PRIVATE
Rationale
Even when a class uses CREATE PRIVATE or CREATE PROTECTED, its instance constructor must be declared in the public section so the runtime and frameworks can instantiate it. Declaring the constructor privately makes reflection and framework integration harder. Keep the constructor in PUBLIC and control creation through the CREATE addition.
Non-Compliant
abap
CLASS zcl_order_service DEFINITION PUBLIC CREATE PRIVATE.
PRIVATE SECTION.
METHODS constructor.
ENDCLASS.Compliant
abap
CLASS zcl_order_service DEFINITION PUBLIC CREATE PRIVATE.
PUBLIC SECTION.
METHODS constructor.
ENDCLASS.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_PUB_CTOR
" SAP CI_ prefix format:
... "#EC CI_PREF_PUB_CTORRelated Rules
- Prefer NEW #( ) over CREATE OBJECT —
#EC PREF_NEW_OPERATOR - Prefer CREATE_* Prefix for Factory Methods Returning Own Class —
#EC PREF_FACTORY_NAME - Design for Inheritance or Prohibit It (FINAL) —
#EC PREF_FINAL_CLASS
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_PUB_CTOR - Implementation File: zcl_skylint_pref_pub_ctor.clas.abap