ABAP Objects Design Patterns – Model View Controller (MVC) Part 2
来源:互联网 发布:java工程师工作量 编辑:程序博客网 时间:2024/05/19 06:15
转载自 By
In this post, we will see how we can implement the MVC (Model-View-Controller) design pattern in ABAP using the Objects. If you have not read the previous discussion about MVC: ABAP Objects Design Patterns – Model View Controller (MVC) Part 1, than I strongly recommond to read that before moving forward.
Demo Application
To implement the MVC, we will create two applications – One will generate an output in ALV and other will generate an output Smartforms. We will put our business logic in the MODEL class. We will create one CONTROL class to establish control between Model and Views.
Our business logic for this example is fairly simple – select the Sales Orders from the VBAK which were created in last ten days. The public method GET_DATA in the class ZCL_MODEL will act as the business logic. Additionally, this class has the public attribute T_VBAK which will be set by the GET_DATA and hold our data from the table.
UML
The UML diagram for any of the application would be like:
Model Class Setup
Model Method Definition
Model Attribute definition
Code Snippet of method GET_DATA
This code would be implemented in the method GET_DATA
* Parameters* Importing IR_ERDAT TYPE TPMY_R_DATE Ranges for date*METHOD get_data.** Get data and save into attribute T_VBAK SELECT * FROM vbak INTO TABLE t_vbak WHERE erdat IN ir_erdat.**ENDMETHOD.
Controller Class Setup
Our controller class ZCL_CONTROL will have a method GET_OBJECT which will give us an object of the model class. We require a public attribute which can refer to the object created in the method GET_OBJECT.
Controller Method definition:
Controller Attributes definition:
Code Snippet for method GET_OBJECT:
* Parameters* Importing IF_NAME TYPE CHAR30 Model class name*METHOD get_object .* DATA: lo_object TYPE REF TO OBJECT.** Generic object reference to importing class CREATE OBJECT lo_object TYPE (if_name). IF sy-subrc = 0.* Downcasting to assign generic object to O_MODEL o_model ?= lo_object. ENDIF.*ENDMETHOD.
In the next post we will see, how we will use the controller class in our view and access the business logic encapsulated in Model class.
Related Links:
- ABAP Objects Design Patterns – Model View Controller (MVC) Part 1
- ABAP Objects Design Patterns – Model View Controller (MVC) Part 3
- ABAP Objects Design Patterns – Model View Controller (MVC) Part 2
- ABAP Objects Design Patterns – Model View Controller (MVC) Part 1
- ABAP Objects Design Patterns – Model View Controller (MVC) Part 3
- Model-View-Controller (MVC)
- Model View Controller(MVC)
- Model-View-Controller(mvc)
- mvc(model view controller)
- MVC(Model-View-Controller)
- MVC模式 "Model-View-Controller"
- MVC(Model-View-Controller)
- Yii - Model-View-Controller (MVC)
- MVC(model-view-controller)
- MVC模型(Model+View+Controller)
- Model-View-Controller MVC模式
- MVC(Model View Controller)是什么?
- Model-View-Controller 编程模式(MVC)
- Model View Controller(MVC) in PHP
- Yii Framework Model-View-Controller (MVC)
- LINUX SCP
- 字符串string 、byte[]、MemoryStream、Base64String的相互转换
- Cookie/Session机制详解
- 最小生成树
- php结合redis实现高并发下的抢购、秒杀功能
- ABAP Objects Design Patterns – Model View Controller (MVC) Part 2
- ElasticSearch检索时特殊字符处理
- maven多模块
- Android开源项目分类汇总
- Python中list和tuple
- Eclipse解决Ctrl+c很卡的方法
- 正则匹配删除redis中大量无用key
- ZOJ1221 Risk
- Nginx平滑升级