Show TOC Start of Content Area

Procedure documentation Defining a Friends Relationship  Locate the document in its SAP Library structure

Use

By default, users of a class may only access its public components. In certain cases you may need to create a closer link between classes. The concept of friends allows you to grant access to explicitly named users (friends) to the protected and private components of a class.

Prerequisites

All the users declared to be friends (classes and interfaces) already exist.

Procedure

In the form-based mode of the Class Builder:

...

       1.      Open the class you want to edit.

       2.      Choose the Friends tab page.

       3.      Switch to change mode.

       4.      Under Friends, enter the classes or interfaces for which you want to permit access to the protected and private components of the defining class. If you specify an interface for Friends, all the classes that implement this interface have access to the protected and private components.

Note

If you choose Modeled only, no entry is made in the class pool. The friends relationship is only displayed and managed in the Class Builder. The friends relationship cannot be used at runtime.

In the source-based mode of the Class Builder:

...

       1.      Open the defining class.

       2.      Switch to change mode.

       3.      Go to the end of the class definition statement and append the addition:

global friends <object1> <object2>.

Result

All the users specified as friends can also access PROTECTED and PRIVATE components of the class in question if the Modeled only flag is not set. The friends relationship is always one-sided and is not inherited. This means that friends of a superclass are not automatically friends of the subclasses.

 

 

End of Content Area