In ABAP OOP, we can nest classes in three ways:
- A class as an attribute of the class
- Inheritance
- Using interfaces
Interfaces are not really a full class. This is due to the fact that, in interfaces, we have only a definition of a class without any implementation. This is important because interfaces in ABAP allow us to implement multi-inheritance. However, we'll turn to that in a moment, in the Inheritance and Interfaces section.
All examples will be shown as a global class created in SE24.
We can create a class as an attribute of the class. To create that attribute, we need to add an attribute, which is typed as TYPE REF TO
. In our example, we'll create an attribute as a reference to the ZCL_ENGINE
class:
In the preceding example, we created an attribute named GR_ENGINE
as an attribute of the ZCL_AUTO
class. After the instantiation of ZCL_AUTO
and the initialization of its GR_ENGINE
attribute, a new object of the ZCL_ENGINE
class is created inside...