What is the View in the MVC standard?

Asked

Viewed 1,906 times

28

I started in 2016 to wear pattern MVC, the concept of Model and Controller I fully understand, but the question of View intrigue me.

What is the View on a model MVC?

I know that’s what the customer sees (data representation), but what can be understood as part of a View?

And in the case of a separate application for the client interface, I can consider this as the View?

In other words: What is part of the View on the server side talking development Web?

  • 2

    View is the GUI. Ex. simplista: in web applications, view is the HTML.

  • @jbueno but it’s only HTML?

  • Yes. The View is the "vision" of your GUI, do you understand? What the user will see.

  • 1
  • Simply and objectively: View is what the user sees. Does nothing on the server part.

2 answers

21


What is the View in an MVC model?

View is the presentation of data, is the output, is how the user will see what was produced by an application action, and is how a data entry will occur and initiate an action by the user.

MVC does not assume to use a client-server architecture, so using these terms makes no sense unless MVC is being used in a web application with this architecture. The MVC can even be applied only on the client side, and technically when it is used on the server side, it is all on the server, after all the view is just creating the HTML page. Even if the context is this, using the words "client" and "server" is something punctual and has nothing to do with the pattern.

So the separation of layers in different instances of the solution is possible, even because the model may be on one server, the controller may be on another, the generator of the view may be on another, as well as the renderer of that view may be on another device (may be a customer).

There is nothing that determines that it should generate HTML, XML, JSON, or anything like that. It can generate a proprietary form of communication, something like a black box that only matters for that application.

what can be understood as part of a View?

It is usually the mechanism that determines what will be rendered to the client, but it is not usually the rendering mechanism (effective drawing). So it has mainly what will be presented, with what characteristics and the way the user should interact with that.

It is common to have some application logic, mainly application and contact mechanisms with other layers. The recommended is to minimize all of this and leave as much as possible only the presentation. Of course not at the cost of harming the user experience.

It is possible that the view communicate with the model, nothing in the pattern dictates that this be prohibited. It is common to avoid this, and recommended. But generally all of these frameworks presupposes strong coupling between the parts. In theory it should not have, but in practice it is impossible not to have. It moved something in the model, it is common to have to touch the controller and mainly in the vision. The diagram taken from Wikipedia clearly shows that they communicate:

MVC

Martin Fowler, who is usually respected on these matters of architecture, shows on your page that communication can occur.

Note that in both articles they do not speak HTML or similar, much less client-server. In fact the default is much older than the web. The fact that he is popular with this technology does not mean that it should only be used like this.

in the case of a separate application for the client interface, I can consider this as the View layer?

It’s possible, but not necessarily. This is a case where if you have a true client-server architecture and the client may have no knowledge of how the server works, you only know how to communicate generically with it. In that case she’s not a view. To the view it presupposes the existence of at least one controller that interacts with it. This occurs in most web sites, but not so much in web applications. In fact it has a lot of web application that the client itself is an MVC by itself and the server at most has a model and a controller, no vision. The same often happens in desktop and mobile applications.

What is part of Server-side View talking about Web development?

It is the assembly of HTML, usually done through templates, but not necessarily. The view not the client rendering. And if it was, it would have two views? It can’t, and it doesn’t make sense.

When you use Angular or something like that there are people who think that the view is the client. It makes no sense, its operation is completely independent.

It’s not very detailed, but the question is not very specific :)

  • @bigown very good answer...

  • @Jcsaint but says the opposite of what you said.

  • 3

    @bigown do not see why it will seem that you are wrong, your answer also had a good acceptance until because it was quite complete, and does not seem to me to say completely the opposite, maybe in the first answer if it could complement with something like "Exemplifying in a Web system would be HTML", both answers served me to remove the doubt, and I believe that both will also be worth reading in the OS :)

  • When a reply full of errors and that says the opposite of mine is accepted, she starts to receive more votes, it should not be so, but it is, then who reads sees the accepted and most voted and thinks that it is the correct one. I have blackened what is the opposite. You can accept whatever you want, I cannot say anything about it, although I consider it a disservice in this case. What I’m going to tell you is not to accept the first answer that someone gives running, even if it’s an answer from me, always wait for others, you induce people to vote and if you’re asking maybe you can’t evaluate well, better wait for more options.

  • 2

    @mustache right, I will take this care next time, but I believe that the fact of giving an example in a web application does not compromise any answer, even why my question hung pro side web.

  • @Felipepaetzold an example is not a problem, as long as it’s clear it’s not just that. Nothing in your question indicates it’s for the web. If so, I think the question should be closed as unclear.

  • 2

    The answer was very good. But I would prefer it to be more focused on continuing to define the "V" of the MVC, than on pointing out the mistakes of the other answer in the question. Otherwise it runs the risk of becoming just a part of a larger context, rather than being able to sustain itself, which is the goal of the site.

  • @Gabe She sustains herself, including because almost all of it was written before the other answer existed. That’s what I wanted to answer. I only pointed out the points that were opposite after I read the other and added reference. It even tends to put more things to reinforce these points, but I thought it was good like this. I can still make something better, but the answer is strong enough to sustain yourself. I could defend more, but you wouldn’t like what I have to say, so I’ll leave a generic defense.

  • 1

    @Bigown I believe that was your intention, but honestly, it’s not the impression you made when you read it. I would love to see it reworked, because the potential is huge.

  • I can only say about what I did, about the impression that other people have I have no control. I’ll even improve, the answer is this.

  • @bigown is absolutely correct, I just think you got too involved in MVC and left the focus of the view explanation. But it’s a great answer.

  • @Ivanferrer I’ll still get better, but when I can do it calmly.

Show 7 more comments

20

What is the View in an MVC model?

Part of the answer to that question is in your other question, when you say that I know what the customer sees (data representation). This view can be via HTML, XML and in applications Desktop see this post JAVA DESKTOP MVC.

What can be understood as part of a View?

View all the part to be displayed to the user.

And in the case of a separate application for the client interface, I can consider this as the View layer?

If the function of this interface is only to show data, yes is the layer of View of its application...

What is part of the View on the server side?

It does nothing, the layer of View does not know of the existence of the database, and the database layer does not know of the existence of the Views. The layer of Controlleris what makes this "bridge" between these two layers. Although it is possible to access the data layer from the ViewsThis is not recommended and departs from the purpose of the MVC

I suggest reading:

  • @Jcsaint Similarly a Json can be considered part of the view?

  • I think the pattern is independent of the platform that will be developed, no?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.