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.
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.
The UML diagram for any of the application would be like:
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.
Model Method Definition
Model Attribute definition
Code Snippet of method GET_DATA |
|
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 |
|
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.
0 comments
Post a Comment