Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Undestanding Design Pattern

Former Member
0 Likes
1,495


Hi All,

.I have read a few blogs  on  design patterns

and have tried my hands on MVC , singleton  and adapter pattern.

Im trying to create an ALV report using Object oriented design patterns

What I would like to know is that how do we break this requirement into classes .I mean how many classes

should I create ??

Which design pattern would be the most appropriate one.

and the most important being - how do I divide the entire report into layers (in order to achieve abstraction)

which will be interconnected to each other.

Thanks,

Faiz

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,417

Hello Faizur,

If this is a simple ALV report I think you can easily mess around with the MVC design pattern.

You can start by implementing three classes:

- Model class - Where you'll have all your business data operations (DB extractions, business rules etc);

- View class - All your ALV operations (eg: alv_display, alv_layout, alv events etc);

- Controller class - This will be the maestro. It should contain both the model and the view instances, and should be responsible for their communication requirements.

For instance:

     Say you have a "Post Document" button on your ALV.

     The view class should never be responsible for document posting operations, what it should do is to trigger an event so that the controller commands the model to post the document. After document posting the model should then send a status report to the controller so that he can pass it to the view.

There is never direct interaction between the model and the view, this is the challenge.

Hope it helps.


Hi All,

.I have read a few blogs  on  design patterns

and have tried my hands on MVC , singleton  and adapter pattern.

Im trying to create an ALV report using Object oriented design patterns

What I would like to know is that how do we break this requirement into classes .I mean how many classes

should I create ??

Which design pattern would be the most appropriate one.

and the most important being - how do I divide the entire report into layers (in order to achieve abstraction)

which will be interconnected to each other.

Thanks,

Faiz

5 REPLIES 5
Read only

sriharsha_parayatham
Participant
0 Likes
1,417

first , already you have classes for ALV .

second , create an interface- for all reports.

ask others to implement that interface, for their reports.

you interface should contain common methods like get data , modify data , build final (any additional methods to handle files , pdf etc..)etc...

another class which can accept object (which is developed using your interface discussed above).

this class (can also be an interface or abstract) will handle displaying ALV using standard classes.

this way you can clearly mark boundaries between logic and display.

if you can handle controls(in separate class or interface) you can call this as MVC.

you don't call any of your data class directly(you can add custom methods to inherited data class and call them in already available methods from interface) , try to call them from the display class or control class(by adding get methods to your data class.

Read only

Former Member
0 Likes
1,418

Hello Faizur,

If this is a simple ALV report I think you can easily mess around with the MVC design pattern.

You can start by implementing three classes:

- Model class - Where you'll have all your business data operations (DB extractions, business rules etc);

- View class - All your ALV operations (eg: alv_display, alv_layout, alv events etc);

- Controller class - This will be the maestro. It should contain both the model and the view instances, and should be responsible for their communication requirements.

For instance:

     Say you have a "Post Document" button on your ALV.

     The view class should never be responsible for document posting operations, what it should do is to trigger an event so that the controller commands the model to post the document. After document posting the model should then send a status report to the controller so that he can pass it to the view.

There is never direct interaction between the model and the view, this is the challenge.

Hope it helps.

Read only

0 Likes
1,417

Thanks Miguel, Your post was quite helpful .

Can you show me a sample program where the MVC pattern is implemented.

Regards,

Faiz

Read only

0 Likes
1,417

Glad it helped.

Unfortunately I don't know of any standard MVC sample, and I have no way of pasting all my implementation in here but check out this design:

This is still MCV but with two views instead of one. What I'm trying to do is to incorporate the Manager design pattern in order to manage all my views. The program should look something like this:

>> MAIN REPORT

  data: o_controller type ref to z_controller.

  START-OF-SELECTION

  create object o_controller.

  o_controller->init().

  o_controller->run().

>> Z_CONTROLLER Class

method init( ).

* Create model and views

create object o_model.

create object o_view_list_alv.

create object o_view_tree_alv.

* Append views to your views list

append o_view_list_alv to t_view.

append o_view_tree_alv to t_view.

endmethod.

method run( ).

* Order model to extract data

t_data = o_model->extract_data().

* Order views to display data

loop at t_view assigning <view>.

     <view>-display( t_data ).

endloop.

endmethod.

Note: This is over simplified pseudo-code, of course you will run into some challenges in order to implement this design.

In this is example the controller is triggering the data extraction and displaying the data in all the required views. Earlier you mentioned that you where interested in abstraction: notice that class z_view is an abstract class and methods display and refresh are only implemented in child view classes.

Hope it helps on your design.

Regards.

Read only

0 Likes
1,417
  • Refer below given document.

       ABAP MVC - Model View Controller Discussion | ABAP Help Blog

Regards,

Philip.