Prefer CREATE_* Prefix for Factory Methods Returning Own Class
WarningClean ABAP & Modern Syntax#EC PREF_FACTORY_NAMERemote Enabled
Overview
Factory methods should start with CREATE_.
ATC Finding Message:
Factory method returning own class type should start with prefix
Rationale
Static factory methods returning an instance of their enclosing class should clearly communicate instantiation intent by following standard naming conventions starting with CREATE_ (e.g. create, create_instance).
Non-Compliant
abap
CLASS-METHODS build RETURNING VALUE(ro_obj) TYPE REF TO lcl_service.Compliant
abap
CLASS-METHODS create_instance RETURNING VALUE(ro_obj) TYPE REF TO lcl_service.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 |
|---|---|---|---|
PREFIX | String | CREATE_ | Required prefix for static factory constructor methods (default: CREATE_) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_FACTORY_NAME
" SAP CI_ prefix format:
... "#EC CI_PREF_FACTORY_NAMERelated Rules
- Design for Inheritance or Prohibit It (FINAL) —
#EC PREF_FINAL_CLASS - Avoid FRIENDS in class definitions —
#EC NO_FRIENDS - Avoid Calling Static Methods via Instance References (->) —
#EC NO_STATIC_ARROW
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_FACTORY_NAME - Implementation File: zcl_skylint_pref_factory_name.clas.abap