• abap objectoriented--基本定义语句


    引用:翱翔云天

    这一节我们来看一下abap oo的定义语句,包括类,方法,事件,属性,接口。

    1. 定义类

    ******************************************
    * Definition part
    ******************************************
    CLASS xxx DEFINITION.
    *------------------------------
    * Public section
    *------------------------------
      PUBLIC SECTION.
        TYPES:
        DATA: 
    *   Static data
        CLASS-DATA:
    *   Methods
        METHODS:
    *     Using the constructor to initialize parameters
           constructor    IMPORTING xxx type yyy,              
    *     Method with parameters
          mm1 IMPORTING iii   TYPE ttt.
    *     Method without parameters
          mm2.
    *   Static methods
        CLASS-METHODS:      
    *---------------------------------------------------*
    * Protected section. Also accessible by subclasses
    *---------------------------------------------------
      PROTECTED SECTION.
    *---------------------------------------------------
    * Private section. Not accessible by subclasses
    *---------------------------------------------------
      PRIVATE SECTION.
    ENDCLASS.
    ******************************************
    * Implementation part
    ******************************************
    CLASS lcl_airplane IMPLEMENTATION.
      METHOD constructor.
      ENDMETHOD.
      METHOD mm1.
      ENDMETHOD.
      METHOD mm2.
      ENDMETHOD.
    ENDCLASS.
     

    2. 定义继承

    CLASS xxx DEFINITION INHERITING FROM yyy.
     

    3. 定义接口

    INTERFACE lif_document
      DATA:          author type ref to lcl_author.
      METHODS:  print,
                display.
    ENDINTERFACE.
    CLASS lcl_text_document DEFINITION.
       PUBLIC SECTION.
          INTERFACES lif_document.
          METHODS     display.
    ENDCLASS.
    CLASS lcl_text_document IMPLEMENTTION.
      METHOD lif_document~print.
      ENDMETHOD.
      METHOD lif_document~display
      ENDMETHOD.
      METHOD display.
      ENDMETHOD.
    ENDCLASS.
    REPORT zzz.
      DATA: text_doc TYPE REF TO lcl_document.
      Start-of-selection.
        CREATE OBJECT text_doc.
        CALL METHOD text_doc->lif_document~print.
        CALL METHOD text_doc->lif_document~display.
    CALL METHOD text_doc->display.
     

    4. 事件

    CLASS <classname> DEFINITION.
      EVENTS: <event> EXPORTING VALUE (<ex_par>) TYPE type.
    CLASS <classname> IMPLEMENTATION.
      METHOD <m>:
        RAISE EVENT <event> EXPORTING <ex_par> = <act_par>.
    Handling events:
    CLASS <classname> DEFINITION.
      METHODS: <on_event> FOR <event> OF {<classname> ! <interface> }
    IMPORTING <imp_par1>...<imp_parN> SENDER.
    Setting handler  
    SET HANDLER <ref_handle> <on_event> FOR {<ref_sender> ! FOR ALL INSTANCES}
               [ACTIVATION <var>]

  • 相关阅读:
    继承与多态——动手又动脑
    类与对象--动手又动脑
    Go语言接口
    GO语言结构体
    GO指针
    GO函数
    GO获取随机数
    GO基础
    Go语言的%d,%p,%v等占位符的使用
    GO语言常量和变量
  • 原文地址:https://www.cnblogs.com/wequst/p/1513454.html
Copyright © 2020-2023  润新知