View previous topic :: View next topic
Author
Message
admin Администратор Joined: 01 Sep 2007 Posts: 1640
Posted: Sat Sep 15, 2007 7:54 pm Post subject: Object Oriented Language Example.
Code: REPORT ZVV0001 line-size 80.
*----------------------------------------------------------------------*
*--- Viktor Voilevich ---*
*--- June 2000 ---*
*----------------------------------------------------------------------*
include <LIST>.
*----------------------------------------------------------------------*
types: t_name(15) type c,
t_icon(4) type c.
*----------------------------------------------------------------------*
interface i_face.
methods: m_show,
m_stat.
data: a_total type i,
a_level type i.
endinterface.
*----------------------------------------------------------------------*
class c_base definition.
public section.
methods: constructor importing value(p_name) type t_name,
m_append importing value(p_c) type ref to c_base,
m_isme returning value(p_name) type t_name.
interfaces i_face.
protected section.
methods: m_name,
m_ad,
m_show.
data a_name type t_name.
class-data a_left type i value 0.
endclass.
*----------------------------------------------------------------------*
class c_derived definition inheriting from c_base.
public section.
methods constructor importing value(p_name) type t_name.
protected section.
methods m_ad redefinition.
endclass.
*----------------------------------------------------------------------*
class c_list definition inheriting from c_derived.
public section.
methods: constructor importing value(p_name) type t_name,
m_append redefinition,
i_face~m_stat redefinition,
m_num returning value(p_num) like sy-tabix.
events e_total exporting value(p_left) type i.
protected section.
methods m_ad redefinition.
private section.
data a_c type table of ref to c_base.
endclass.
*----------------------------------------------------------------------*
class c_icon definition inheriting from c_base.
public section.
methods constructor importing value(p_name) type t_name
value(p_icon) type t_icon.
protected section.
methods: m_ad redefinition,
m_draw.
private section.
data a_icon type t_icon.
endclass.
*----------------------------------------------------------------------*
class c_total definition.
public section.
methods m_total for event e_total of c_list importing p_left sender.
endclass.
*----------------------------------------------------------------------*
class c_base implementation.
method constructor.
a_name = p_name.
endmethod.
method m_append.
endmethod.
method m_isme.
p_name = a_name.
endmethod.
method m_name.
write at /a_left a_name.
endmethod.
method m_ad.
write: ': I am BASE instance...'.
endmethod.
method m_show.
call method: m_name,
m_ad.
endmethod.
method i_face~m_show.
add 2 to a_left.
call method me->m_show.
subtract 2 from a_left.
endmethod.
method i_face~m_stat.
add 1 to i_face~a_total.
if i_face~a_level is initial.
add 1 to i_face~a_level.
endif.
endmethod.
endclass.
*----------------------------------------------------------------------*
class c_derived implementation.
method constructor.
call method super->constructor exporting p_name = p_name.
endmethod.
method m_ad.
write: ': I am DERIVED instance...'.
endmethod.
endclass.
*----------------------------------------------------------------------*
class c_list implementation.
method constructor.
call method super->constructor exporting p_name = p_name.
endmethod.
method m_append.
append p_c to a_c.
endmethod.
method m_num.
describe table a_c lines p_num.
endmethod.
method m_ad.
data: w_c type ref to c_base,
w_i type ref to i_face.
write ': I am LIST instance... - here are my items:'.
loop at a_c into w_c.
new-line.
w_i = w_c.
call method w_i->m_show.
endloop.
raise event e_total exporting p_left = a_left.
endmethod.
method i_face~m_stat.
data: w_c type ref to c_base,
w_i type ref to i_face,
w_level like i_face~a_level.
call method super->i_face~m_stat.
if not a_c[] is initial.
loop at a_c into w_c.
w_i = w_c.
call method w_i->m_stat.
add w_i->a_total to i_face~a_total.
if w_level < w_i->a_level.
w_level = w_i->a_level.
endif.
endloop.
add w_level to i_face~a_level.
endif.
endmethod.
endclass.
*----------------------------------------------------------------------*
class c_icon implementation.
method constructor.
call method super->constructor exporting p_name = p_name.
a_icon = p_icon.
endmethod.
method m_ad.
write ': I am ICON instance...'.
call method m_draw.
endmethod.
method m_draw.
write a_icon as icon.
endmethod.
endclass.
*----------------------------------------------------------------------*
class c_total implementation.
method m_total.
data: w_name type t_name,
w_num like sy-tabix.
w_name = sender->m_isme( ).
w_num = sender->m_num( ).
write at /p_left w_name color col_total.
if w_num > 0.
write: '--- Total', w_num, 'items.'.
else.
write: '--- Is Empty.'.
endif.
endmethod.
endclass.
*----------------------------------------------------------------------*
data: i_1 type ref to i_face,
o_1 type ref to c_base,
o_2 type ref to c_base,
o_t type ref to c_total.
*======================================================================*
START-OF-SELECTION.
*----------------------------------------------------------------------*
create object o_1 type c_list exporting p_name = '1st - List'.
create object o_2 type c_icon exporting p_name = '2nd - Icon'
p_icon = ICON_GREEN_LIGHT.
call method o_1->m_append exporting p_c = o_2.
create object o_2 type c_icon exporting p_name = '3rd - Icon'
p_icon = ICON_POSITIVE.
call method o_1->m_append exporting p_c = o_2.
create object o_2 type c_list exporting p_name = '4th - List'.
call method o_2->m_append exporting p_c = o_1.
create object o_1 type c_base exporting p_name = '5th - Base'.
call method o_2->m_append exporting p_c = o_1.
create object o_1 type c_derived exporting p_name = '6th - Derived'.
call method o_2->m_append exporting p_c = o_1.
create object o_1 type c_icon exporting p_name = '7th - Icon'
p_icon = ICON_SUM.
call method o_2->m_append exporting p_c = o_1.
create object o_1 type c_list exporting p_name = '8th - List'.
call method o_2->m_append exporting p_c = o_1.
create object o_1 type c_list exporting p_name = '9th - List'.
call method o_1->m_append exporting p_c = o_2.
create object o_2 type c_base exporting p_name = '10th - Base'.
call method o_1->m_append exporting p_c = o_2.
create object o_2 type c_derived exporting p_name = '11th - Derived'.
call method o_1->m_append exporting p_c = o_2.
create object o_2 type c_icon exporting p_name = '12th - Icon'
p_icon = ICON_CHECKED.
call method o_1->m_append exporting p_c = o_2.
create object o_t.
*======================================================================*
END-OF-SELECTION.
*----------------------------------------------------------------------*
i_1 = o_1.
set handler o_t->m_total for all instances.
call method: i_1->m_show, i_1->m_stat.
uline.
write: / 'Total', i_1->a_total, 'objects on', i_1->a_level, 'levels.'.
Back to top
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.