Chinaunix首页 | 论坛 | 博客
  • 博客访问: 481431
  • 博文数量: 199
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2020-05-14 13:25
个人简介

代码5S

文章分类

全部博文(199)

文章存档

2021年(5)

2020年(194)

我的朋友

分类: 其他平台

2020-10-30 08:37:45


点击(此处)折叠或打开

  1. *&---------------------------------------------------------------------*
  2. *& report zdemo05
  3. *&---------------------------------------------------------------------*
  4. *&
  5. *&---------------------------------------------------------------------*
  6. REPORT z_interface.

  7. INTERFACE status.
  8.   METHODS write.
  9. ENDINTERFACE.

  10. CLASS counter DEFINITION.
  11.   PUBLIC SECTION.
  12.     INTERFACES status.

  13.     METHODS increment.

  14.   PRIVATE SECTION.
  15.     DATA count TYPE i.
  16. ENDCLASS.

  17. CLASS counter IMPLEMENTATION.
  18.   METHOD status~write.
  19.     cl_demo_output=>write_text( |count in counter is { count } | ).
  20.   ENDMETHOD.

  21.   METHOD increment.
  22.     count = count + 1.
  23.   ENDMETHOD.
  24. ENDCLASS.

  25. CLASS bicycle DEFINITION.
  26.   PUBLIC SECTION.
  27.     INTERFACES status.

  28.     METHODS drive.
  29.   PRIVATE SECTION.
  30.     DATA speed TYPE i.
  31. ENDCLASS.

  32. CLASS bicycle IMPLEMENTATION.
  33.   METHOD status~write.
  34.     cl_demo_output=>write_text( |speed of bicycle is { speed } | ).
  35.   ENDMETHOD.

  36.   METHOD drive.
  37.     speed = speed + 10.
  38.   ENDMETHOD.
  39. ENDCLASS.

  40. START-OF-SELECTION.
  41.   DATA(count) = NEW counter( ).
  42.   DATA(bike) = NEW bicycle( ).

  43.   DO 5 TIMES.
  44.     count->increment( ).
  45.     bike->drive( ).
  46.   ENDDO.

  47.   count->status~write( ).
  48.   bike->status~write( ).

  49.   DATA status_tab TYPE TABLE OF REF TO status WITH EMPTY KEY.

  50.   status_tab = VALUE #( ( count )
  51.                         ( bike ) ).

  52.   LOOP AT status_tab ASSIGNING FIELD-SYMBOL(<status>).
  53.     <status>->write( ).
  54.   ENDLOOP.
  55.   cl_demo_output=>display( ).

阅读(1298) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~