Help with MVC, I'm a newbie u.u

0

Get me out of doubt, for example when doing a program with mvc, since the view sends the messages to the controller so that this in turn sends the message to the model, then in the model goes the logic of the application, in the controller is the bridge between the view and the model, and ps the model only receives the actions made by the user and gives the respective answers, my question is as follows: When making a desktop application for example: a login, the person writes their respective user and password, and this travels to the controller which will ask the model if it is correct or not, because where I write the messages that will be returned to the user, incorrect password example, I write it in the model, controller or in the view, I can explain please.

Another query: When doing the validations for example of numbers, I believe in the model a validator class, which I call it in the controller ?, or simply what is valid in the model, which ps for the login example, when I enter the wrong password from the model with a method return a String with the message.

If you were so kind in answering me and if it is with a basic example it would be better, thank you.

    
asked by Jerson Ramirez Ortiz 03.02.2018 в 01:22
source

1 answer

0

You see, in a MVC (Model View Controller, or Model View Controller) it is a type of design pattern, of which there are several.

MVC is characterized by having a Controller that is responsible for determining which Vista to present to the user, according to the action executed by it. In the MVC, each action in a View is correlated to something that the Controller must attend, and depending on the action, it can make HTTP requests, add a new element, and so on.

The View is just a representation of the Model, which is usually a Database or something similar.

In summary: The Model is almost always a Database; a View is just the representation that is given to the BD; The Controller interacts directly with the View to respond to actions performed on it, and performs predetermined actions.

Now, to answer your questions:

  • In the first example, (sorry if I'm wrong, I have not worked on desktop for a while) You should write a response code to those events, that this code changes the login view a bit in this one case. In other words, you write in the Controller what you want to happen to the Vista depending on the validity of the credentials: A message, delete the TextFields, etc ...
  • If you want to perform validations of some kind, you must do it first in the Controller, because this is precisely that, which controls what data pass and modify something, and which not . If you want to know if the password is incorrect, then from the controller send a query to the BD and ask for the password of the user, then you take the one that entered the login, compare and depending on the result, the Controller acts according to what Say what to do.

I hope you have been able to clarify your doubts a bit, I recommend reading this post in SO to know more.

    
answered by 04.02.2018 в 04:27