‎2011 Dec 14 10:07 AM
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
‎2011 Dec 14 11:13 AM
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
‎2011 Dec 14 11:16 AM
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
‎2011 Dec 14 11:42 AM
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
‎2011 Dec 20 4:48 AM
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.
‎2011 Dec 28 4:08 PM
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
‎2011 Dec 29 4:19 AM
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
‎2011 Dec 29 11:12 PM
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
‎2012 Jan 05 9:37 AM
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
‎2012 Jan 25 5:47 AM
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