Rule Definition
There can be situations in which it is necessary to protect a whole class from uncontrolled specialization. This could be suitable, for example, if changes must be made to a class without any subclasses becoming syntactically or semantically incorrect.
For a final definition, use the FINAL addition in the CLASS statement.
Remediation
Check if the class could be inherited. If not, then add the FINAL addition in its definition.
Violation Code Sample
* This class must not be subclassed
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS:
set
IMPORTING VALUE
(set_value) TYPE i, increment,
get
EXPORTING VALUE
(get_value) TYPE i.
PRIVATE SECTION.
DATA count TYPE i.
ENDCLASS.
Fixed Code Sample
* This class must not be subclassed
CLASS counter DEFINITION FINAL.
PUBLIC SECTION.
METHODS:
set
IMPORTING VALUE
(set_value) TYPE i, increment,
get
EXPORTING VALUE
(get_value) TYPE i.
PRIVATE SECTION.
DATA count TYPE i.
ENDCLASS.
Reference
An insider's guide to writing robust, understandable, maintainable, state-of-the-art ABAP programs - Part 2
Andreas Blumenthal - Horst Keller
Related Technologies
Technical Criterion
Programming Practices - OO Inheritance and Polymorphism
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.