Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

super_class

Former Member
0 Likes
585

what is meaning of super_class

4 REPLIES 4
Read only

uwe_schieferstein
Active Contributor
0 Likes
546

Hello Sandeep

The super class is, as the name implies, the class from which the sub-classes are inheriting.

Within the sub-classes you can call methods of the super class using:

  CALL METHOD super->method( ).

Regards

Uwe

Read only

Former Member
0 Likes
546

Hi Sandeep,

In object oriented programming there is a property called Inheritance.

In inheritabce common components exist only once in the superclass, so they can be maintained centrally – generalization. This provides a better structure for the software.

Subclasses inherit all the main characteristics of superclass – specialization.

So redundant implementations is avoided. Subclasses contain extensions / changes i.e. they can also add new components and replace the

implementations with inherited methods.

<u><b>Advantages of Inheritance are -</b></u>

Centralized maintenance.

Safe, generic method of access.

Entire software component can be easily extended.

Please see the followoing program.

&----


*& Class (Definiton) zl_lcl_vehicle

&----


  • Definition of the Superclass

----


CLASS zl_lcl_vehicle DEFINITION.

PUBLIC SECTION.

  • Visible to all

METHODS: set_make IMPORTING im_make TYPE string

im_model TYPE string,

get_make EXPORTING ex_make TYPE string

ex_model TYPE string.

PROTECTED SECTION.

  • Visible within class and all subclasses

DATA gv_n_o_veh TYPE i.

PRIVATE SECTION.

  • Only visible within the class

DATA: gv_make TYPE string, " Vehicle make

gv_model TYPE string. " Type or model

ENDCLASS. "zl_lcl_vehicle DEFINITION

&----


*& Class (Definiton) zl_lcl_vehicle

&----


  • Definition of the Subclass

----


CLASS zl_lcl_car DEFINITION INHERITING FROM zl_lcl_vehicle.

PUBLIC SECTION.

METHODS: set_vehtype IMPORTING im_vehtype TYPE string

im_n_o_veh TYPE i,

get_vehtype EXPORTING ex_vehtype TYPE string

ex_n_o_veh TYPE i.

PRIVATE SECTION.

DATA gv_vehtype TYPE string.

ENDCLASS. "zl_lcl_car DEFINITION

&----


*& Class (Implementation) zl_lcl_vehicle

&----


  • Implementation of the Superclass

----


CLASS zl_lcl_vehicle IMPLEMENTATION.

METHOD set_make.

IF im_make IS NOT INITIAL

AND im_model IS NOT INITIAL.

gv_make = im_make.

gv_model = im_model.

ENDIF.

ENDMETHOD. "set_make

METHOD get_make.

ex_make = gv_make.

ex_model = gv_model.

ENDMETHOD. "get_make

ENDCLASS. "zl_lcl_vehicle

&----


*& Class (Implementation) zl_lcl_car

&----


  • Implementation of the Subclass

----


CLASS zl_lcl_car IMPLEMENTATION.

METHOD set_vehtype.

IF im_vehtype IS NOT INITIAL.

gv_vehtype = im_vehtype.

*Protected component of superclass can be directly accessed in subclass.

**

*The same applies for public components, private components of

*superclass *

*have to be accessed using public or protected methods of superclass.

**

gv_n_o_veh = im_n_o_veh.

ENDIF.

ENDMETHOD. "set_vehtype

METHOD get_vehtype.

ex_vehtype = gv_vehtype.

ex_n_o_veh = gv_n_o_veh.

ENDMETHOD. "get_vehtype

ENDCLASS. "zl_lcl_car

  • Declaring a reference variable with reference to the subclass.

DATA z_car TYPE REF TO zl_lcl_car.

DATA: gv_make TYPE string,

gv_model TYPE string,

gv_vehtype TYPE string,

gv_n_o_veh TYPE i.

START-OF-SELECTION.

  • Creating an instance of the subclass

CREATE OBJECT z_car.

  • Accessing the public methods of superclass

z_car->set_make( EXPORTING im_make = 'MARUTI'

im_model = '800' ).

z_car->get_make( IMPORTING ex_make = gv_make

ex_model = gv_model ).

  • Accessing the methods of subclass

z_car->set_vehtype( EXPORTING im_vehtype = 'Car'

im_n_o_veh = '10' ).

z_car->get_vehtype( IMPORTING ex_vehtype = gv_vehtype

ex_n_o_veh = gv_n_o_veh ).

WRITE: / 'Vehicle type :', gv_vehtype,

/ 'Make :', gv_make,

/ 'Model :', gv_model,

/ 'No of ordered vehicles :', gv_n_o_veh.

<b>Award points if useful.</b>

Regards

Indrajit

Read only

Former Member
0 Likes
546

hi,

super class is nothing but normal calss, we called the class as super class only if we derived subclass from the exisisting class.

Inheritance allows you to derive a new class from an existing class. You do this using the INHERITING FROM addition in the

<b>CLASS <subclass> DEFINITION INHERITING FROM <superclass>.</b>

statement. The new class <subclass> inherits all of the components of the existing class <superclass>. The new class is called the subclass of the class from which it is derived. <b>The original class is called the superclass of the new class.</b>

in object oriented abap, OBJECT class is the super class for all the exisisting classes.

follow this sample program for knowing the super class.

REPORT demo_inheritance.

CLASS counter DEFINITION.
  PUBLIC SECTION.
    METHODS: set IMPORTING value(set_value) TYPE i,
             increment,
             get EXPORTING value(get_value) TYPE i.
   PROTECTED SECTION . 
    DATA count TYPE i.
ENDCLASS.

CLASS counter IMPLEMENTATION.
  METHOD set.
    count = set_value.
  ENDMETHOD.
  METHOD increment.
    ADD 1 TO count.
  ENDMETHOD.
  METHOD get.
    get_value = count.
  ENDMETHOD.
ENDCLASS.

CLASS counter_ten DEFINITION INHERITING FROM counter. 
  PUBLIC SECTION.
    METHODS increment REDEFINITION . 
    DATA count_ten.
ENDCLASS.

CLASS counter_ten IMPLEMENTATION.
  METHOD increment.
    DATA modulo TYPE I.
     CALL METHOD super->increment . 
    write / count.
    modulo = count mod 10.
    IF modulo = 0.
      count_ten = count_ten + 1.
      write count_ten.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

DATA: count TYPE REF TO counter,
      number TYPE i VALUE 5.

START-OF-SELECTION.

   CREATE OBJECT count TYPE counter_ten .

  CALL METHOD count->set EXPORTING set_value = number.

  DO 20 TIMES.
    CALL METHOD count->increment.
  ENDDO.

The class COUNTER_TEN is derived from COUNTER. It redefines the method INCREMENT. To do this, you must change the visibility of the COUNT attribute from PRIVATE to PROTECTED. The redefined method calls the obscured method of the superclass using the pseudoreference SUPER->. The redefined method is a specialization of the inherited method.

The example instantiates the subclass. The reference variable pointing to it has the type of the superclass. When the INCREMENT method is called using the superclass reference, the system executes the redefined method from the subclass.

regards,

Ashk Reddy

Read only

Former Member
0 Likes
546

Hi,

Super class is noting but a class having sub classes.i,e any class can be derived from super class.

reward points if usefull