Hi,
Recently I had this requirement of displaying a report with financial data, the report must display 3 ALVs in the screen. Now i've been reading about design patterns lately and this is the perfect opportunity to put into practice.
Since the requirement is to show 3 ALVS, I decided to create 3 instances of my view class, below is kind of a class diagram
the start-of-selection event triggers the program
START-OF-SELECTION. lcl_application=>start_of_selection( it_bukrs = s_bukrs[] iv_bupa = pa_kunnr iv_ryear = pa_ryear ).
This method creates the model, the view and the controller
* Crea modelo MVC, establece parámetros de selección y conecta el controlador con el modelo me->create_model( it_bukrs = it_bukrs iv_ryear = iv_ryear iv_bupa = iv_bupa ). * Crea vista MVC, en este caso ALV me->create_view( ). * Ejecuta la lógica del programa - Consulta a la base de datos y procesa datos * lo_controller->mo_model->run_business_logic( ). mo_model->run_business_logic( ).
Create_view is pretty straightforward, just instantiates one view per ALV
METHOD create_view. mo_view_asset = NEW lcl_view_assets( ). mo_view_liabi = NEW lcl_view_liabil( ). mo_view_total = NEW lcl_view_total( ). ENDMETHOD.
Then there's the run_business_logic, which gets data from the DB through other objects and process them into 3 internal tables, one for each display
METHOD run_business_logic. * Búsquedas a la base de datos me->run_db_selection( ). * Proceso la información obtenida en el paso anterior me->process_selected_data( ). ENDMETHOD.
Soo far so good, all the data I need is contained in these 3 internal tables.
Now the problem is to decouple the views from the main program, I was not able to achieve the separation of concerns and ended up with 3 global internal tables and view objects, which I pass from the model class like this
mo_model->run_business_logic( ). gt_assets = mo_model->mt_assets. gt_liabil = mo_model->mt_liabil. gt_total = mo_model->mt_total. go_view_top = mo_view_asset. go_view_mid = mo_view_liabi. go_view_bot = mo_view_total. CALL SCREEN 0100.
Really horrible solution, I've been reading about putting the screen within a function group and define an interface to handle the screen, but I have no idea how to achieve this. Still struggling with the concept of interfaces within OOP.
Can you help me on this?
Many thanks,
Marco