Access superclass member function

How can I access a super class method from a child class method?

Here is an example that illustrates the problem: Let's say we have two classes

class parent definition.
public section.
  methods f.
endclass.

class child definition inheriting from parent.
public section.
  methods f redefinition.
  methods g.
endclass.

Now, in the implementation g, we want to call the implementation of the superclass fsimilar to the following syntactically incorrect fragment

class child implementation.
  method g.
    super->f( ). "forbidden: super-> can only be used to call the previous implementation of the same method
  endmethod.
endclass.

As indicated in the comment, super->it is impossible to use . You can help?


After some googling, it was suggested to copy the implementation parent->finto child->g, is this really the only way to do this?


Actual use case

@vwegert , f . parent - , child - . child->f - , . child , g. g, parent->f.

+4
2

- , ( ) g, f, , , super->f. . , , - , , , , .

+1

do_f f do_f . . , "" f.

REPORT zzy.

CLASS parent DEFINITION.
  PUBLIC SECTION.
    METHODS f.
  PROTECTED SECTION.
    METHODS do_f.
ENDCLASS.

CLASS parent IMPLEMENTATION.
  METHOD f.
    do_f( ).
  ENDMETHOD.

  METHOD do_f.
    WRITE / 'Parent' f'.
  ENDMETHOD.
ENDCLASS.

CLASS child DEFINITION INHERITING FROM parent.
  PUBLIC SECTION.
    METHODS:
      f REDEFINITION,
      g.
ENDCLASS.

CLASS child IMPLEMENTATION.
  METHOD f.
    WRITE / 'Child' f'.
  ENDMETHOD.

  METHOD g.
    do_f( ).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA(lo_child) = NEW child( ).
  lo_child->g( ).
  lo_child->f( ).
0

Source: https://habr.com/ru/post/1649888/


All Articles