Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. REPORT yoo_events.
  2.  
  3. CLASS chef DEFINITION.
  4. PUBLIC SECTION.
  5. METHODS: call_service.
  6. EVENTS: call_for_waiter.
  7. ENDCLASS.
  8.  
  9.  
  10. CLASS customer DEFINITION.
  11. PUBLIC SECTION.
  12. METHODS: constructor IMPORTING VALUE(i_tablenumber) TYPE i,
  13. call_for_assistance.
  14. *step 1, class defines an event (events, class-events)
  15. EVENTS: call_for_waiter EXPORTING VALUE(e_tablenumber) TYPE i. "can only exporting and by value
  16.  
  17. PROTECTED SECTION.
  18. DATA tablenumber TYPE i.
  19. ENDCLASS.
  20.  
  21. CLASS waiter DEFINITION.
  22. PUBLIC SECTION.
  23. METHODS: constructor IMPORTING i_who TYPE string,
  24. *step 3, handler class defines and implements the handler method
  25. go_see_the_chef FOR EVENT call_for_waiter OF chef, "event handler method
  26. go_see_the_customer FOR EVENT call_for_waiter OF customer
  27. IMPORTING e_tablenumber. "can only be importing and use the same name of the parameter declared exporting
  28. PROTECTED SECTION.
  29. DATA who TYPE string.
  30. ENDCLASS.
  31.  
  32. CLASS chef IMPLEMENTATION.
  33. METHOD call_service.
  34. WRITE: / 'Chef calling WAITER EVENT'.
  35. *step 2, object or class triggers the event
  36. RAISE EVENT call_for_waiter.
  37. WRITE: / 'Chef calling WAITER EVENT complete'.
  38. ULINE.
  39. ENDMETHOD.
  40. ENDCLASS.
  41.  
  42. CLASS customer IMPLEMENTATION.
  43. METHOD constructor.
  44. tablenumber = i_tablenumber.
  45. ENDMETHOD.
  46.  
  47. METHOD call_for_assistance.
  48. WRITE: / 'Customer calling WAITER EVENT'.
  49. RAISE EVENT call_for_waiter
  50. EXPORTING e_tablenumber = tablenumber.
  51. WRITE: / 'Customer calling WAITER EVENT complete'.
  52. ULINE.
  53. ENDMETHOD.
  54. ENDCLASS.
  55.  
  56. CLASS waiter IMPLEMENTATION.
  57. METHOD: constructor.
  58. who = i_who.
  59. ENDMETHOD.
  60.  
  61. METHOD: go_see_the_chef.
  62. WRITE: / who, 'goes to see the chef'.
  63. ENDMETHOD.
  64.  
  65. METHOD: go_see_the_customer.
  66. WRITE: / who, 'goes to see the customer at table:', e_tablenumber.
  67. ENDMETHOD.
  68. ENDCLASS.
  69.  
  70. DATA: o_chef TYPE REF TO chef,
  71. o_customer_1 TYPE REF TO customer,
  72. o_customer_2 TYPE REF TO customer.
  73.  
  74. DATA: o_head_waiter TYPE REF TO waiter,
  75. o_waiter TYPE REF TO waiter.
  76.  
  77. START-OF-SELECTION.
  78. CREATE OBJECT o_chef.
  79. CREATE OBJECT o_customer_1 EXPORTING i_tablenumber = 2.
  80. CREATE OBJECT o_customer_2 EXPORTING i_tablenumber = 5.
  81.  
  82. CREATE OBJECT o_head_waiter EXPORTING i_who = 'Sarah the head waiter'.
  83. CREATE OBJECT o_waiter EXPORTING i_who = 'Bob the waiter'.
  84.  
  85. *step 4, handler object or handler class is registered to events at runtime
  86. set HANDLER: o_head_waiter->go_see_the_chef FOR o_chef,
  87. o_waiter->go_see_the_customer FOR ALL INSTANCES.
  88.  
  89. CALL METHOD: o_chef->call_service,
  90. o_customer_1->call_for_assistance,
  91. o_customer_2->call_for_assistance.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement