Changing Visibility of Members
In an ABAP class or ABAP interface, you can move a member definition between the public, protected, and private sections in order to switch its availability.
Prerequisites
Context
This refactoring option can be triggered for the following member types:
- Types
- Constants
- Attributes
- Methods
- Events
- Aliases
Example
| Before Execution | After Execution |
|---|---|
To copy the source code example, click here Code Example Before Execution |
|
|
The speed attribute is declared in the private section. |
The declaration of the speed attribute has has been removed from the private section and added in the public section. |
Some refactoring aids decrease (public > protected > private > local) the visibility of members of a class.
So, if the visibility of the target section is more restrictive than in the current section, the refactoring will check whether any usages exist that will no longer be available after the change. In this case, the developer is informed and can decide to reject or apply the change.
Increasing VisibilitySome refactoring aids increase (local > private > protected > public) the visibility of members or locals inside a class.
So, if the visibility of a member (or local) is increased, subsequent processing might depend on other declarations that are no longer visible for the member. In this case, the developer is informed and can decide to reject or apply the change.
Procedure
- In the definition part, position the cursor on the member you want to move to another section.
- Get the quick assist proposals by choosing Quick Fix from the context menu (shortcut Ctrl 1) or by using the Quick Assist view.
- Apply Make 'member' protected, Make 'member' public, or Make 'member' private. Note that the corresponding refactoring options for the possible target sections will be displayed depending on the current cursor position.