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

Regarding objects

Former Member
0 Likes
555

Why we go for redifintion in subclasses and when we go

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
533

Hi

All subclasses contain the components of all classes between themselves and the root node in an inheritance tree. The visibility of a component cannot be changed. However, you can use the REDEFINITION addition in the METHODS statement to redefine an inherited public or protected instance method in a subclass and make its function more specialized. When you redefine a method, you cannot change its interface. The method retains the same name and interface, but has a new implementation.

The method declaration and implementation in the superclass is not affected when you redefine the method in a subclass. The implementation of the redefinition in the subclass obscures the original implementation in the superclass.

Any reference that points to an object of the subclass uses the redefined method, even if the reference was defined with reference to the superclass. This particularly applies to the self-reference ME->. If, for example, a superclass method M1 contains a call CALL METHOD [ME->]M2, and M2 is redefined in a subclass, calling M1 from an instance of the subclass will cause the original method M2 to be called, and calling M1 from an instance of the subclass will cause the redefined method M2 to be called.

Within a redefine method, you can use the pseudoreference SUPER-> to access the obscured method. This enables you to use the existing function of the method in the superclass without having to recode it in the subclass.

if use ful regard with points.

regards ,

shanthi

4 REPLIES 4
Read only

Former Member
0 Likes
533

in the abstarct class we can't implement the method.

it has to be implement it's one of the subclass.To implement that method we need to redefine it with redefinition keyword.

ex:-

CLASS C1 DEFINITION ABSTRACT.

PUBLIC SECTION.

METHODS : METH1 ABSTRACT.

ENDCLASS.

CLASS C1 IMPLEMENTATION .

ENDCLASS.

CLASS C2 DEFINITION INHERITING FROM C1.

public section.

methods : meth1 redefinition.

ENDCLASS.

CLASS C2 IMPLEMENTATION.

METHOD : METH1.

WRITE:/5 'I am method: METH1 '.

ENDMETHOD.

endclass.

START-OF-SELECTION.

data : OREF2 TYPE REF TO C2.

CREATE OBJECT oref2.

Read only

Former Member
0 Likes
533

Hi ,

In Inhertance super class may have same method name of sub class method , here we declare the method with redefination and give addittional or different functionality for the method in sub class. you can not only add new components, but also provide inherited methods with

new implementations. This is known as redefinition.If you redefine a method, you do not need to enter its interface again in the subclass, but only the name of the method.

If help ful regard with points.

bye

Read only

Former Member
0 Likes
534

Hi

All subclasses contain the components of all classes between themselves and the root node in an inheritance tree. The visibility of a component cannot be changed. However, you can use the REDEFINITION addition in the METHODS statement to redefine an inherited public or protected instance method in a subclass and make its function more specialized. When you redefine a method, you cannot change its interface. The method retains the same name and interface, but has a new implementation.

The method declaration and implementation in the superclass is not affected when you redefine the method in a subclass. The implementation of the redefinition in the subclass obscures the original implementation in the superclass.

Any reference that points to an object of the subclass uses the redefined method, even if the reference was defined with reference to the superclass. This particularly applies to the self-reference ME->. If, for example, a superclass method M1 contains a call CALL METHOD [ME->]M2, and M2 is redefined in a subclass, calling M1 from an instance of the subclass will cause the original method M2 to be called, and calling M1 from an instance of the subclass will cause the redefined method M2 to be called.

Within a redefine method, you can use the pseudoreference SUPER-> to access the obscured method. This enables you to use the existing function of the method in the superclass without having to recode it in the subclass.

if use ful regard with points.

regards ,

shanthi

Read only

Former Member