Skip to Content
0
Former Member
Sep 18, 2004 at 03:35 PM

Dynamic access to own private components?

36 Views

Hi,

problem: a private attribute or method can be

accessed by the own methods - but NOT by those

methods inherited from the father object.

A minimalistic program demonstrating the problem

is the following. When you run it, observe that

the dynamic method call fails, although the method

is implied in the instance i1 doing the call.

-

-


report zz_handle_event.

class o definition.

public section.

data: event type string.

methods: handle_event.

endclass.

class o implementation.

method handle_event.

data: lv_handler type string.

concatenate 'HANDLE_' event into lv_handler.

call method me->(lv_handler).

endmethod.

endclass.

class o1 definition inheriting from o.

private section.

methods: handle_evt_1, handle_evt_4.

endclass.

class o1 implementation.

method handle_evt_1.

  • Do something

endmethod.

method handle_evt_4.

  • Do something different

endmethod.

endclass.

class o2 definition inheriting from o.

private section.

methods: handle_evt_2, handle_evt_3.

endclass.

class o2 implementation.

method handle_evt_2.

  • Do something even more different

endmethod.

method handle_evt_3.

  • Do something else

endmethod.

endclass.

START-OF-SELECTION.

data: i1 type ref to o1.

create object i1.

i1->event = 'EVT_1'.

i1->handle_event( ).

-

-


Stupid workarounds:

- making the event handlers handle_evt_1 etc. public,

contradicting to the model: The methods are

not designed for external calls.

- copying the coding of method handle_event into

each instance - contradicting the software reuse

principle.

Any better idea?

Regards,

Rüdiger