Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REPORT yoo_events.
- CLASS chef DEFINITION.
- PUBLIC SECTION.
- METHODS: call_service.
- EVENTS: call_for_waiter.
- ENDCLASS.
- CLASS customer DEFINITION.
- PUBLIC SECTION.
- METHODS: constructor IMPORTING VALUE(i_tablenumber) TYPE i,
- call_for_assistance.
- *step 1, class defines an event (events, class-events)
- EVENTS: call_for_waiter EXPORTING VALUE(e_tablenumber) TYPE i. "can only exporting and by value
- PROTECTED SECTION.
- DATA tablenumber TYPE i.
- ENDCLASS.
- CLASS waiter DEFINITION.
- PUBLIC SECTION.
- METHODS: constructor IMPORTING i_who TYPE string,
- *step 3, handler class defines and implements the handler method
- go_see_the_chef FOR EVENT call_for_waiter OF chef, "event handler method
- go_see_the_customer FOR EVENT call_for_waiter OF customer
- IMPORTING e_tablenumber. "can only be importing and use the same name of the parameter declared exporting
- PROTECTED SECTION.
- DATA who TYPE string.
- ENDCLASS.
- CLASS chef IMPLEMENTATION.
- METHOD call_service.
- WRITE: / 'Chef calling WAITER EVENT'.
- *step 2, object or class triggers the event
- RAISE EVENT call_for_waiter.
- WRITE: / 'Chef calling WAITER EVENT complete'.
- ULINE.
- ENDMETHOD.
- ENDCLASS.
- CLASS customer IMPLEMENTATION.
- METHOD constructor.
- tablenumber = i_tablenumber.
- ENDMETHOD.
- METHOD call_for_assistance.
- WRITE: / 'Customer calling WAITER EVENT'.
- RAISE EVENT call_for_waiter
- EXPORTING e_tablenumber = tablenumber.
- WRITE: / 'Customer calling WAITER EVENT complete'.
- ULINE.
- ENDMETHOD.
- ENDCLASS.
- CLASS waiter IMPLEMENTATION.
- METHOD: constructor.
- who = i_who.
- ENDMETHOD.
- METHOD: go_see_the_chef.
- WRITE: / who, 'goes to see the chef'.
- ENDMETHOD.
- METHOD: go_see_the_customer.
- WRITE: / who, 'goes to see the customer at table:', e_tablenumber.
- ENDMETHOD.
- ENDCLASS.
- DATA: o_chef TYPE REF TO chef,
- o_customer_1 TYPE REF TO customer,
- o_customer_2 TYPE REF TO customer.
- DATA: o_head_waiter TYPE REF TO waiter,
- o_waiter TYPE REF TO waiter.
- START-OF-SELECTION.
- CREATE OBJECT o_chef.
- CREATE OBJECT o_customer_1 EXPORTING i_tablenumber = 2.
- CREATE OBJECT o_customer_2 EXPORTING i_tablenumber = 5.
- CREATE OBJECT o_head_waiter EXPORTING i_who = 'Sarah the head waiter'.
- CREATE OBJECT o_waiter EXPORTING i_who = 'Bob the waiter'.
- *step 4, handler object or handler class is registered to events at runtime
- set HANDLER: o_head_waiter->go_see_the_chef FOR o_chef,
- o_waiter->go_see_the_customer FOR ALL INSTANCES.
- CALL METHOD: o_chef->call_service,
- o_customer_1->call_for_assistance,
- o_customer_2->call_for_assistance.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement