ABAP Objects: Overriding (Redefinition)
来源:互联网 发布:mac怎么用html5看视频 编辑:程序博客网 时间:2024/05/21 17:42
Lets check out how we can implement Overriding in ABAP Objects. This is also known as the Redefinition of the method.
When do we need to use the Overriding:
Overriding is useful, when we want to extend the functionality of the inherited method. For example: we have a generic class of CAR and it has method DRIVE. We derived a subclass, say COROLLA, from that class. Now, we need to change the functionality in DRIVE method of the subclass COROLLA. In this situation we can “Redefine” the method DRIVE. This redefinition of the method is called Overriding.
Code Lines
In ABAP, we have extension REDEFINTION of keyword METHODS to be able to implement the Overriding functionality.
REPORT ZOVERRIDING.*----------------------------------------------------------------------** Definition of CAR class*----------------------------------------------------------------------*CLASS lcl_car DEFINITION. PUBLIC SECTION. METHODS: drive, Color.ENDCLASS. "LCL_CAR DEFINITION**----------------------------------------------------------------------** Implementation of CAR Class*----------------------------------------------------------------------*CLASS lcl_car IMPLEMENTATION. METHOD drive. WRITE: / 'You are driving a Car'. ENDMETHOD. "drive METHOD COLOR. WRITE: / 'Your car has BLUE color'. ENDMETHOD.ENDCLASS. "LCL_CAR IMPLEMENTATION**----------------------------------------------------------------------** Definition of COROLLA - Inheriting from CAR class*----------------------------------------------------------------------*CLASS lcl_corolla DEFINITION INHERITING FROM lcl_car. PUBLIC SECTION. METHODS: drive REDEFINITION.ENDCLASS. "LCL_COROLLA DEFINITION**----------------------------------------------------------------------** Implementation of COROLLA*----------------------------------------------------------------------*CLASS lcl_corolla IMPLEMENTATION.* Here we are overriding the functionality of the drive method.* We are adding some functionality which are specific to COROLLA class METHOD drive. CALL METHOD super->drive. WRITE: / 'which is Corolla', / 'Do you like it?'. ENDMETHOD. "driveENDCLASS. "LCL_COROLLA IMPLEMENTATION*START-OF-SELECTION.** Object for COROLLA DATA: lo_corolla TYPE REF TO lcl_corolla. CREATE OBJECT lo_corolla. CALL METHOD lo_corolla->drive. CALL METHOD lo_corolla->color.
0 0
- ABAP Objects: Overriding (Redefinition)
- ABAP OBJECTS OVEWVIEW
- SAP DEMO-ABAP Objects
- ABAP--OBJECTS ABAP的类的基础知识
- ABAP--OBJECTS ABAP的类的基础知识
- ABAP--OBJECTS ABAP的类的基础知识
- Dependency of abap dictionary objects
- Tree report with ABAP Objects
- Dependency of abap dictionary objects
- java中重载(Overloading)、重写(Overriding)、重定义(redefinition)
- Multiple ALVs on Single Screen Using ABAP Objects
- overloading & overriding
- overriding && overloading
- Overriding && Overloading
- java overriding
- ABAP Trial Version for Newbies: Part 8 ' Exporting development objects from SP8 '
- ABAP CDS 替代对象(Replacement Objects)引起的数据错误
- ABAP Objects Design Patterns – Model View Controller (MVC) Part 1
- zoj 1076 Gene Assembly
- hdoj 4901 多校联合4 1005
- Row
- 翻译的国外大牛的教程【fatal error C1083: 无法打开包括文件:“SDKDDKVer.h”】亲测有效!
- PO BO VO DTO POJO DAO概念及其作用(附转换图)
- ABAP Objects: Overriding (Redefinition)
- POJ 3613 Cow Relays floyd+快速幂
- DB-DAY 5 JavaScript的disabled属性
- SVN update: 'skipped' message
- 读HandlerMapping子类RequestMappingHandlerMapping源码
- Androiid备份短信
- 使用mysqli 之后的 php中文乱码问题要点
- 浙大计算机实验室详细推介
- Ubuntu 中安装低版本的gcc/g++