cancel
Showing results for 
Search instead for 
Did you mean: 

MVC: Can View be the Controller's friend?

daniel_humberg
Contributor
0 Kudos

Whenever I want to use a method or attribute of a controller inside a view (<%=controller->attribute%>), the attribute has to be public. I often run into the case that an attribute is only used inside the controller AND on the view, but nowhere else. If the view would be a class, I could add it as a "friend" to the controller class and the view would have access to the attribute although it's private. But since a view is not a class, I guess there is not much I can do except setting the attributes to public, right?

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Ironically your view is a class. However it is dynamically generated and has a name something like the following - CL_O2AF3WTE8WB4I3SOYJU1VR1ZWQ5. So I don't think there would be any opportunity to setup a friend relationship.

I'm curious though, I almost never create attributes in my Controller (and when I do they are always private or protected). If I want to share any data with my view, I do that through my Model Class. Perhaps this is just a matter of style, but I was wondering what benefits you see in sharing attributes from the controller to the view?

daniel_humberg
Contributor
0 Kudos

For more complex classes, I also use a model. But often, I have small view with small controllers where I avaoid the effort to create a model. In these cases, the view normally gets its data from methods or attributes of the controller.

Answers (0)