Feature request: Standardize order of class components
Hi Jörg-Michael, I'd like to request a new rule to standardize the order of class components in the class definition.
Clean Code suggests the following order:
- Static constants
- Private static variables
- Private instance variables
- Functions
Of course, we can't use this 1:1 because ABAP classes are structured using SECTIONs. Adapting these general guidelines for ABAP classes, a possible standardized order could look like this:
INTERFACESTYPESCONSTANTSCLASS-DATADATACLASS-METHODSMETHODS
I imagine that a common variant of this approach would be this:
- [...]
CLASS-DATACLASS-METHODSDATAMETHODS
The same approach could be used for interface definitions.
What do you think about this?
EDIT: I removed the list entry for ENUM because it is covered by TYPES already.
Please keep in mind that the statements in the definition sections can "only look up". Some maybe not so obvious relations that would have to be considered to not cause syntax errors with your suggested order:
CONSTANTS some_constant_value TYPE i VALUE 42.
INTERFACES my_interface DATA VALUES read_only_attribute = some_constant_value.
DATA instance_attribute TYPE i.
CLASS-DATA static_attribute LIKE instance_attribute.
TYPES: BEGIN OF ENUM my_enum,
a,
END OF ENUM my_enum.
TYPES: BEGIN OF line,
component TYPE my_enum,
END OF line.
DATA some_attribute TYPE i.
TYPES some_type LIKE some_attribute.