Entering content frameProcedure documentation Defining Friends Relationships Locate the document in its SAP Library structure

Use

Generally users of a class may only access the public components of that class. Sometimes, however, you might want to create a closer link between classes. The concept of friends could be of use here.
In this case a class can permit explicitly named users (friends) to access its protected and private components.

Prerequisites

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

Procedure

  1. Select the defining class and change to the Class Editor.
  2. Choose Friends.
  3. Go 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, this means that all the classes that implement this interface have access to the protected and private components.

Note

If you set the flag to 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.

Result

All the users specified as friends can also access PROTECTED a nd PRIVATE components of the class in question if the Modeled only flag was not set in step 4. 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.

 

 

Leaving content frame