• 事件


    *&---------------------------------------------------------------------*
    *& Report  ZTEST20131106_2
    *&
    *&---------------------------------------------------------------------*
    *&
    *&关于事件的实例
    *&---------------------------------------------------------------------*
    
    REPORT  ztest20131106_2.
    *----------------------------------------------------------------------*
    *       CLASS vehicle DEFINITION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS vehicle DEFINITION INHERITING FROM object.  "定义类vehicle,这边是继承基类object.
      PUBLIC SECTION.
        EVENTS:too_fast.        "定义事件too_fast
        METHODS:accelerate,
                show_speed.
      PROTECTED SECTION.
        DATA speed TYPE i.
    ENDCLASS.                    "vehicle DEFINITION
    *----------------------------------------------------------------------*
    *       CLASS vehicle IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS vehicle IMPLEMENTATION. "方法的实现
      METHOD accelerate.
        speed = speed + 1.  
        IF speed > 5.
          RAISE EVENT too_fast. " 在方法accelerate中触发事件too_fast,静态事件需要通过静态方法中触发
          speed = 5.
    
        ENDIF.
      ENDMETHOD.                    "accelerate
      METHOD show_speed.
        WRITE: / 'Speed:',speed.
      ENDMETHOD.                    "show_speed
    ENDCLASS.                    "vehicle IMPLEMENTATION
    *----------------------------------------------------------------------*
    *       CLASS handler DEFINITION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS handler DEFINITION.          "定义类handler
      PUBLIC SECTION.
        METHODS handle_excess "在handler类下定义事件too_fast的处理方法handle_excess ,FOR EVENT too_fast OF vehicle说明事件是在vehicle类下的
        FOR EVENT too_fast OF vehicle.
    ENDCLASS.                    "handler DEFINITION
    *----------------------------------------------------------------------*
    *       CLASS handler IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS handler IMPLEMENTATION. "方法的实现
      METHOD handle_excess.
        WRITE: / 'Speed can not be too fast..'.
    *          speed = 10.
      ENDMETHOD.                    "handle_excess
    ENDCLASS.                    "handler IMPLEMENTATION
    
    DATA: o_vehicle TYPE REF TO vehicle, "定义类的引用
          o_handle TYPE REF TO handler.
    
    START-OF-SELECTION.
      CREATE OBJECT:o_vehicle,o_handle. "创建类得实例
      SET HANDLER o_handle->handle_excess FOR ALL INSTANCES.  "注册事件处理方法,这边FOR ALL INSTANCES是为处理器注册所有可以触发该事件的实例,如
    
    果是for o_vehicle表示指定注册到o_vehicle下的事件。如果是静态事件则不需要for附加项
      DO 11 TIMES.
        CALL METHOD o_vehicle->accelerate.
        CALL METHOD o_vehicle->show_speed.
    
      ENDDO.
    View Code
  • 相关阅读:
    【转】SVN linux命令及 windows相关操作(二)
    【转】SVN linux命令及 windows相关操作(一)
    spring框架DI(IOC)和AOP 原理及方案
    [转载]JVM性能调优--JVM参数配置
    JVM性能调优-GC内存模型及垃圾收集算法
    密码运算API(GP Internal API)
    时间API(GP Internal API)
    可信存储API(GP Internal API)
    内存管理函数(GP Internal API)
    Panic(GP Internal API)
  • 原文地址:https://www.cnblogs.com/caizjian/p/3433851.html
Copyright © 2020-2023  润新知