Created
September 24, 2016 17:53
-
-
Save furlan/196e161b2da31c01739ba7d8ffc016f6 to your computer and use it in GitHub Desktop.
Modelo Anêmico em ABAP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| REPORT z_anemic_model. | |
| CLASS order_item DEFINITION DEFERRED. | |
| TYPES: order_item_table TYPE TABLE OF REF TO order_item WITH NON-UNIQUE DEFAULT KEY. | |
| CLASS order DEFINITION. | |
| PUBLIC SECTION. | |
| METHODS get_total RETURNING VALUE(order_total) TYPE i. | |
| METHODS set_total IMPORTING order_total TYPE i. | |
| METHODS get_items RETURNING VALUE(order_items) TYPE order_item_table. | |
| METHODS set_items IMPORTING order_items TYPE order_item_table. | |
| PRIVATE SECTION. | |
| DATA items TYPE order_item_table. | |
| DATA total TYPE i. | |
| ENDCLASS. | |
| CLASS order IMPLEMENTATION. | |
| METHOD get_total. | |
| order_total = me->total. | |
| ENDMETHOD. | |
| METHOD set_total. | |
| me->total = order_total. | |
| ENDMETHOD. | |
| METHOD get_items. | |
| order_items = me->items. | |
| ENDMETHOD. | |
| METHOD set_items. | |
| me->items = order_items. | |
| ENDMETHOD. | |
| ENDCLASS. | |
| CLASS order_item DEFINITION. | |
| PUBLIC SECTION. | |
| METHODS get_price RETURNING VALUE(item_price) TYPE i. | |
| METHODS set_price IMPORTING item_price TYPE i. | |
| METHODS get_quantity RETURNING VALUE(item_quantity) TYPE i. | |
| METHODS set_quantity IMPORTING item_quantity TYPE i. | |
| PRIVATE SECTION. | |
| DATA price TYPE i. | |
| DATA quantity TYPE i. | |
| ENDCLASS. | |
| CLASS order_item IMPLEMENTATION. | |
| METHOD get_price. | |
| item_price = me->price. | |
| ENDMETHOD. | |
| METHOD set_price. | |
| me->price = item_price. | |
| ENDMETHOD. | |
| METHOD get_quantity. | |
| item_quantity = me->quantity. | |
| ENDMETHOD. | |
| METHOD set_quantity. | |
| me->quantity = item_quantity. | |
| ENDMETHOD. | |
| ENDCLASS. | |
| CLASS order_service DEFINITION. | |
| PUBLIC SECTION. | |
| CLASS-METHODS calculate_total IMPORTING order TYPE REF TO order. | |
| ENDCLASS. | |
| CLASS order_service IMPLEMENTATION. | |
| METHOD calculate_total. | |
| DATA order_items TYPE order_item_table. | |
| DATA item TYPE REF TO order_item. | |
| DATA items_total TYPE i. | |
| order_items = order->get_items( ). | |
| LOOP AT order_items INTO item. | |
| items_total = items_total + ( item->get_price( ) * item->get_quantity( ) ). | |
| ENDLOOP. | |
| order->set_total( items_total ). | |
| ENDMETHOD. | |
| ENDCLASS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment