Open
Description
Proposed Rule
In some cases, it can be enough to have references to enum classes for distinctions. The whole thing works fine as long as you are within the same thread.
CLASS /clean/message_severity DEFINITION PUBLIC CREATE PRIVATE FINAL.
PUBLIC SECTION.
CLASS-DATA warning TYPE REF TO /clean/message_severity READ-ONLY,
CLASS-DATA error TYPE REF TO /clean/message_severity READ-ONLY.
DATA value TYPE symsgty READ-ONLY.
CLASS-METHODS class_constructor.
METHODS constructor IMPORTING value TYPE symsgty.
ENDCLASS.
CLASS /clean/message_severity IMPLEMENTATION.
METHOD class_constructor.
warning = NEW #( 'W' ).
error = NEW #( 'E' ).
ENDMETHOD.
METHOD constructor.
me->value = value.
ENDMETHOD.
ENDCLASS.
Anti Pattern:
CLASS /clean/message_severity DEFINITION PUBLIC CREATE PRIVATE FINAL.
PUBLIC SECTION.
CLASS-DATA warning TYPE REF TO /clean/message_severity READ-ONLY,
CLASS-DATA error TYPE REF TO /clean/message_severity READ-ONLY.
CLASS-METHODS class_constructor.
METHODS constructor IMPORTING value TYPE symsgty.
ENDCLASS.
CLASS /clean/message_severity IMPLEMENTATION.
METHOD class_constructor.
warning = NEW #( ).
error = NEW #( ).
ENDMETHOD.
METHOD constructor.
me->value = value.
ENDMETHOD.
ENDCLASS.
Justification
If you pass an instance to a parallel process, for example, or serialize/deserialize this instance, there is a problem if you compare the references with each other because they are no longer the same. The instance passed from outside and the instance newly created via the class_constructor differ, although in both cases it is an instance of e.g. Warning. To prevent such problems, an enum Instance should always contain a value that can be checked against.