Academia ABAP - AP02 - Aula 02 - OO - 05 - Polimorfismo
Academia ABAP - AP02 - Aula 02 - OO - 05 - Polimorfismo
Academia ABAP - AP02 - Aula 02 - OO - 05 - Polimorfismo
TYPE-POOLS icon.
INCLUDE ziab2006_11_01.
START-OF-SELECTION.
r_carrier->add_airplane( r_passenger ).
r_carrier->add_airplane( r_cargo ).
r_carrier->display_attributes( ).
===============================================================================
* ------ ziab2006_11_01
*variaveis publicas
PUBLIC SECTION.
CONSTANTS:
pos_1 TYPE i VALUE 30.
METHODS:
constructor
IMPORTING
im_name TYPE string
im_planetype TYPE saplane-planetype,
display_attributes.
CLASS-METHODS:
display_n_o_airplanes,
get_n_o_airplanes RETURNING value(re_count) TYPE i.
*Variaveis privadas
PRIVATE SECTION.
METHODS:
get_technical_attributes
IMPORTING
im_type TYPE saplane-planetype
EXPORTING
ex_weight TYPE s_plan_wei
ex_tankcap TYPE s_capacity.
DATA:
name TYPE string,
planetype TYPE saplane-planetype.
CLASS-DATA:
n_o_airplanes TYPE i.
ENDCLASS. "lcl_airplane DEFINITION
* ---------------------------
* sub-classe LCL_CARGO_PLANE
* ---------------------------
*variaveis publicas
PUBLIC SECTION.
METHODS:
constructor
IMPORTING
im_name TYPE string
im_planetype TYPE saplane-planetype
im_cargo TYPE scplane-cargomax.
METHODS:
display_attributes REDEFINITION.
*variaveis privadas
PRIVATE SECTION.
DATA:
max_cargo TYPE scplane-cargomax.
ENDCLASS. "lcl_cargo_plane DEFINITION
METHOD display_attributes.
super->display_attributes( ).
WRITE: / 'Max cargo: ', max_cargo.
ULINE.
ENDMETHOD. "display_attributes
* -------------------------------
* sub-classe LCL_PASSENGER_PLANE
* -------------------------------
METHODS:
display_attributes REDEFINITION.
*variaveis privadas
PRIVATE SECTION.
DATA:
max_seats TYPE sflight-seatsmax.
ENDCLASS. "lcl_passenger_plane DEFINITION
METHOD display_attributes.
super->display_attributes( ).
WRITE: / 'Max seats: ', max_seats.
ULINE.
ENDMETHOD. "display_attributes
ENDCLASS. "lcl_passenger_plane IMPLEMENTATION
* -----------------------
* sub-classe LCL_CARRIER
* -----------------------
*variaveis privadas
PRIVATE SECTION.
DATA:
name TYPE string,
airplane_list TYPE TABLE OF REF TO lcl_airplane.
ENDCLASS. "lcl_carrier DEFINITION
METHOD constructor.
name = im_name.
ENDMETHOD. "constructor
METHOD add_airplane.
APPEND im_plane TO airplane_list.
ENDMETHOD. "add_airplane
METHOD display_attributes.
WRITE: icon_flight AS ICON, name. ULINE. ULINE.
display_airplanes( ).
ENDMETHOD. "display_attributes
METHOD display_airplanes.
DATA: r_plane TYPE REF TO lcl_airplane.
LOOP AT airplane_list INTO r_plane.
r_plane->display_attributes( ).
ENDLOOP.
ENDMETHOD. "display_airplanes