Last active
August 24, 2016 20:10
-
-
Save furlan/2872468 to your computer and use it in GitHub Desktop.
ZABAP101_FACTORY_PATTERN
This file contains 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 ZABAP101_FACTORY_PATTERN | |
*& | |
*&---------------------------------------------------------------------* | |
*& | |
*& | |
*&---------------------------------------------------------------------* | |
REPORT zabap101_factory_pattern. | |
*----------------------------------------------------------------------* | |
* CLASS lcl_command DEFINITION | |
*----------------------------------------------------------------------* | |
* | |
*----------------------------------------------------------------------* | |
CLASS lcl_command DEFINITION ABSTRACT. | |
PUBLIC SECTION. | |
CLASS-METHODS factory | |
IMPORTING | |
im_command TYPE string | |
RETURNING value(re_instance) TYPE REF TO lcl_command | |
RAISING cx_sy_create_object_error. | |
METHODS get_command_description. | |
ENDCLASS. "lcl_command IMPLEMENTATION | |
*----------------------------------------------------------------------* | |
* CLASS lcl_command IMPLEMENTATION | |
*----------------------------------------------------------------------* | |
* | |
*----------------------------------------------------------------------* | |
CLASS lcl_command IMPLEMENTATION. | |
METHOD factory. | |
DATA: lv_command TYPE string. | |
CONCATENATE 'lcl_' im_command INTO lv_command. | |
TRANSLATE lv_command TO UPPER CASE. | |
CREATE OBJECT re_instance TYPE (lv_command). | |
ENDMETHOD. "lcl_command | |
METHOD get_command_description. | |
WRITE: / 'Command definition: '. | |
ENDMETHOD. "factory | |
ENDCLASS. "lcl_command DEFINITION | |
*----------------------------------------------------------------------* | |
* CLASS lcl_task DEFINITION | |
*----------------------------------------------------------------------* | |
* | |
*----------------------------------------------------------------------* | |
CLASS lcl_task DEFINITION INHERITING FROM lcl_command. | |
PUBLIC SECTION. | |
METHODS: get_command_description REDEFINITION. | |
ENDCLASS. "lcl_task DEFINITION | |
*----------------------------------------------------------------------* | |
* CLASS lcl_task IMPLEMENTATION | |
*----------------------------------------------------------------------* | |
* | |
*----------------------------------------------------------------------* | |
CLASS lcl_task IMPLEMENTATION. | |
METHOD get_command_description. | |
WRITE: / 'Command task, determine a task to someone.'. | |
ENDMETHOD. "get_command_description | |
ENDCLASS. "lcl_task IMPLEMENTATION | |
*----------------------------------------------------------------------* | |
* CLASS lcl_question DEFINITION | |
*----------------------------------------------------------------------* | |
* | |
*----------------------------------------------------------------------* | |
CLASS lcl_question DEFINITION INHERITING FROM lcl_command. | |
PUBLIC SECTION. | |
METHODS: get_command_description REDEFINITION. | |
ENDCLASS. "lcl_question DEFINITION | |
*----------------------------------------------------------------------* | |
* CLASS lcl_question IMPLEMENTATION | |
*----------------------------------------------------------------------* | |
* | |
*----------------------------------------------------------------------* | |
CLASS lcl_question IMPLEMENTATION. | |
METHOD get_command_description. | |
WRITE: / 'Command question, request some answer to someone.'. | |
ENDMETHOD. "get_command_description | |
ENDCLASS. "lcl_question IMPLEMENTATION | |
DATA: r_command TYPE REF TO lcl_command. | |
PARAMETERS: p_comm TYPE string. | |
START-OF-SELECTION. | |
TRY . | |
r_command = lcl_command=>factory( p_comm ). | |
r_command->get_command_description( ). | |
CATCH cx_sy_create_object_error. | |
WRITE: / 'Syntax error.'. | |
CATCH cx_root. | |
WRITE: / 'Internal error.'. | |
ENDTRY. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment