>属性
->方法
class lcl_product definition.
public section.
events: pricechanged.
methods:
raise_event. "
private section.
data: price type i.
endclass. "lcl_product DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_product IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_product implementation.
method raise_event.
write: / '------------------------------------'.
write: / 'Before event trrigger'.
raise event pricechanged. "
write: / 'After event trrigger'.
write: / '------------------------------------'.
endmethod. "raise_event
endclass. "lcl_product IMPLEMENTATION
*----------------------------------------------------------------
* CLASS lcl_customer
*----------------------------------------------------------------
class lcl_customer definition.
public section.
methods:
handle_price_changed for event pricechanged of lcl_product
importing sender.
endclass. "lcl_customer DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_customer IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_customer implementation.
method handle_price_changed.
write: / ' Customer handle changed price'.
endmethod. "handle_price_changed
endclass. "lcl_customer IMPLEMENTATION
*----------------------------------------------------------------
* CLASS lcl_logger
*----------------------------------------------------------------
class lcl_logger definition.
public section.
methods:
handle_price_changed for event pricechanged of lcl_product
importing sender.
endclass. "lcl_logger DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_logger IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_logger implementation.
method handle_price_changed.
write: / ' Logger log changed price'.
endmethod. "handle_price_changed
endclass. "lcl_logger IMPLEMENTATION
* Create object instances
start-of-selection.
data:grf_product type ref to lcl_product,
grf_customer type ref to lcl_customer,
grf_logger type ref to lcl_logger.
create object grf_product.
create object grf_customer.
create object grf_logger.
* Register event
set handler grf_customer->handle_price_changed for grf_product.
set handler grf_logger->handle_price_changed for grf_product.
* Trigger event
grf_product->raise_event( ).