cancel
Showing results for 
Search instead for 
Did you mean: 

Assitance class to read table data & MVC

Former Member
0 Kudos

Hi All,

One of my friend demonstrated a ABAP webdynpro code to me. He used a assistance class to access the data in the ABAP table from an action / event handler method of a view.

I suggested that this may not align with best practices of webdynpro's intended MVC paradigm. My suggestion is that a event handler should call a method in the Component Controller and the method in the component controller should call the assistance class. This based on the general view : any class modelling the database table will be considered as a Model and a View may not access the Model directly without going through the controller.

But he did not agree with it. Hence I request webdynpro experts in the forum to express their opinion and enhance my knowledge about best practices for ABAP webdynpro.

Thanks in advance

Regards,

Arul

Accepted Solutions (1)

Accepted Solutions (1)

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Assistance class generally comes into play when a group of people are working on some object and some validation codes and some helper codes keeps on repeating, We can put the code in this class and can be shared by every developer in their component.( it may include some data base fetching statements )

Where there are Data Manipulation which are specific to one component, we create a custom controller which only deal with that particular change and call the appropriate class methods or function modules inside the Custom controller

Abhi

Former Member
0 Kudos

Thansk for your reply.

In our example that assitance class was particularly used to read the data from tables and the assitance class is called from the View directly without either using component controller or a custom controller. My view is that the a function module or a class or an assitance class may be used to access the data in the tables but they may not be called directly from the view. is that your understanding too?

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Yes,Web Dynpro will not stop you calling the classmethods from view's controller, but it is good practice to call any database accesses from the component or custom controller level not touching the View. It is clearly our job to enforce MVC

Abhi

Answers (2)

Answers (2)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> This based on the general view : any class modelling the database table will be considered as a Model and a View may not access the Model directly without going through the controller.

>

> Regards,

> Arul

See to me the key there is that the View may not directly access the Model. The View (layout design) really can't directly access the Model in Web Dynpro. It is the View Controller that is doing so. Therefore in my mind it is still MVC to call a method of the assistance class from the View Controller. MVC doesn't specify the level of the controller that should be used.

That said it is a good practice to put many of your model calls (those that are reusable) in the component controller. That way you have consistency in the way that you interact with the model and code is more maintainable if it is easier to find. However if you have a call to the model that interacts with just one view or you have a small component that only has one view I personally don't feel that it is a violation to make calls from the assistance class from the view. For instance you might have some model logic that controls the visibility of elements on a particular view.

Former Member
0 Kudos

Hi Thomas,

Thanks for your reply.

>

> See to me the key there is that the View may not directly access the Model. The View (layout design) really can't directly access the Model in Web Dynpro. It is the View Controller that is doing so. Therefore in my mind it is still MVC to call a method of the assistance class from the View Controller. MVC doesn't specify the level of the controller that should be used.

>

I agree with your opinion above. Based on my understanding, View controller can access the data that it requires to manipulate/control the screens , visibility etc on the screen. I also agree that there is nothing wrong in using an assitance class to read the table data directly from View Controller where there is only one view . is it not an exception rather than a rule when it comes to describing best practices?.

Arul

Former Member
0 Kudos

Hi,

We can call the assistance class methods in view but then it violates MVC architecture.

So best way is to call assistance class methods from component controller.