Skip to content

Latest commit

 

History

History
34 lines (21 loc) · 1.7 KB

number-public-attributes.md

File metadata and controls

34 lines (21 loc) · 1.7 KB

code pal for ABAP

code pal for ABAP > Documentation > Number of Public Attributes Check

Number of Public Attributes Check

What is the Intent of the Check?

The Number of Public Attributes Check counts the number of public attributes up to a maximum (usually 0). All attributes and methods should be private by default. The data encapsulation principle helps you to protect your attributes from being changed and adds readability for others, they only see what they need.

How does the check work?

This Check counts only DATA and CLASS-DATA within a global or local, CLASS DEFINITION or INTERFACE. Inherited attributes and CONSTANTS aren't counted. A structure is counted as one attribute, no matter how many attributes are in the structure.

Which attributes can be maintained?

Attributes

How to solve the issue?

Make those attributes PRIVATE or PROTECTED. You can grant the read access with a getter method (for example, get_user_first_name). With a setter, you can also grant write access and have the possibility to validate the inserted data (for example, set_time_in_seconds with a test to allow only positive numbers).

What to do in case of exception?

You can suppress Code Inspector findings generated by this check using the pseudo comment "#EC NUM_PUBLIC_ATTR.
The pseudo comment must be placed right after the class definition header.

CLASS class_name DEFINITION.   "#EC NUM_PUBLIC_ATTR
  PUBLIC SECTION.
    DATA attribute1 TYPE i.
    DATA attribute2 TYPE i.
ENDCLASS.