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

Create superclass from subclass ?

h_senden2
Active Contributor
0 Likes
5,383

In SE24 i've build a class with attributes/methods (public/protected), but now i want to create a superclass from that (sub)class where some attributes/methods are not in the superclass, but in the subclass.

Is there a easy way in SE24 to create a superclass from the subclass ?

Or should i do this manually ?

regards,

Hans

9 REPLIES 9
Read only

Former Member
0 Likes
3,372

Hi,

We can not create a super class from sub class this is not possible .

i.e,

Sub Class can inherits the properties of super Class .

Warm Regards,

PavanKumar.G

Edited by: pavankumar.g on Dec 20, 2011 9:55 AM

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
3,372

You can create a sub class inheriting from super class and if required you can redefine the functionalities but not the other way you said.

"Parents are born first...only then the children"

Kesav

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,372

You can use the [Refactoring Assistant|http://help-abap.zevolving.com/2011/09/class-editor-refactoring-assistant-i/] integrated in the Class Builder to build the class hierarchy.

BR,

Suhas

Read only

Former Member
0 Likes
3,372

HI Senden,

You can Create subclass using superclass and access their method and Properties but You can't create superclass using subclass.

Thanks & Regards

Naveen Subramani.

Read only

Clemenss
Active Contributor
0 Likes
3,372

Hans,

just copy your class to a new (super) class. Then delete what you do not want in the super class. Then change the inheritance of the original to make it the subclass. Delete what you already have in the supe class. OK, may take 5-10 minutes.

I don't know what the refactoring assistant (available from ABAP 702?) can do for you.

Regards,

Clemens

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,372

Hello Clemens,

I don't know what the refactoring assistant (available from ABAP 702?) can do for you.

Refactoring assistant is available from ECC6.0. It is a DnD tool which helps you rebuild your class hierarchy!

BR,

Suhas

Read only

Arthur_Silva
Participant
0 Likes
3,372

Hi Senden, You must create the parents first with the protected or public methods. Than later you be able to construct the children. You can override the method using polymorphism. For example:


*----------------------------------------------------------------------*
*       CLASS cl_employer DEFINITION
*----------------------------------------------------------------------*
CLASS cl_employer DEFINITION .
  PUBLIC SECTION .
    METHODS: get_salary  RETURNING value(salary)  TYPE f .
  PRIVATE SECTION .
    DATA salary TYPE f  VALUE 100 .
ENDCLASS .                    "cl_employer DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_employer IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_employer IMPLEMENTATION .
  METHOD get_salary .
    salary  = me->salary * 80 .
  ENDMETHOD .                    "cl_employer
ENDCLASS .                    "cl_employer IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS cl_manager DEFINITION
*----------------------------------------------------------------------*
CLASS cl_manager  DEFINITION INHERITING FROM cl_employer .
  PUBLIC SECTION .
    METHODS get_salary REDEFINITION .
  PRIVATE SECTION .
    DATA salary TYPE f  VALUE 100 .
ENDCLASS .                    "cl_manager DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_manager IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_manager  IMPLEMENTATION .
  METHOD get_salary .
    salary = me->salary * 100 .
  ENDMETHOD .
ENDCLASS .                    "cl_manager IMPLEMENTATION

START-OF-SELECTION .
DATA e1 TYPE REF TO cl_employer .  CREATE OBJECT e1 .
DATA e2 TYPE REF TO cl_employer .  CREATE OBJECT e2 TYPE cl_manager .

e1->get_salary( ) .
e2->get_salary( ) .

Don't forget to set a superclass in transaction SE24 on tab PROPERTIES. Also, you can set the attribute FINAL to childrens.

Best regards,

Arthur

Read only

Former Member
0 Likes
3,372

This is not possible. You cannot inherit the (super) class from the (sub)class and change the hierarchy later. Hierarchy change would remove the inherited methods and attributes. You would need to create the (super) class manually.

Regards,

Suhas

Read only

former_member226225
Contributor
0 Likes
3,372

Hi,

Inheritance is defined as inheriting the properties of super class to sub class .

so we can create the subclasses based up on the super classes . so, we cant create the super classes based up on the sub classes.

This is not possible

Thanks & Regards,

Raghunadh.K