Where does the user enter in MVC architecture?

I would like to know where the controller gets user input from (to feed the model with). Since the input medium is strongly associated with the user, should not we understand the idea of ​​a specific method of obtaining user data? But how can I separate the controller from the view? Is it possible to make both completely independent of each other, as their goals suggest?

Example: When I have an application that uses the curses library for presentation, it means that it is only available through the terminal. Using curses methods to read user data in a controller will break encapsulation, but calling methods in a view will have nothing to do with model rendering.

+4
source share
5 answers

Consider View and Controller interact through an observer pattern . The controller registers as an observer with a view. When a user enters data into a view and presses Enter, then the view interprets the data and notifies its observers of the availability of data. The controller can then retrieve data from the view through a public method.

+1
source

IN MVC, the controller gets its user input from the view.

+3
source

I do not think that the presentation is really very important for the data entry actually. I find MVC a lot easier to visualize if you see that the user is directly communicating with the controller. The controller receives data from the user and sends views back. In many systems, the viewing mechanism has some limited way of self-learning (i.e., text inputs display what is printed before it is sent to the controller). But for any architecture such as MVC, you can replace any view with any other view if they are both capable of processing the same data.

For instance. User name input can be performed on any system that supports string input. The controller accepts the string and therefore can be used in a web application, terminal application, or graphics application.

+1
source

I think the view should have a callback on the controller to send through user input. In web architecture, callbacks are provided through the ability to send user input back to the server via HTTP requests.

In your case, the ncurse front should probably have some kind of callback method for the controller component in order to send user input back.

0
source

Well,

I will try to be more specific to you. Providing vague / abstract answers for ppl that you can see doesn't master the subject doesn't help.

MVC β†’ Model View Controler

There are many MVC implementations, I don’t know your case, but I will give you one.

The most common MVC implementation is as follows.

view ↔ Controler ↔ Model

In a web script.

The presentation will be your HTML pages and data entry will take place on the form.

<form action=/home/createuser method=post> ...code goes here... </form> 

Home will be your controller (a class called home), and createuser will be in the house.

 public class Home extends Controller { public void createUser(Userform f){ ...create user... } } 

This form will send data to the method as parameters. Createuser would process them to talk to the model, and then save the data, if so.

0
source

All Articles