tags:

views:

116

answers:

5

I'd like to know where the controller gets the user input from (to feed the model with). Because input media is strongly related to the user shouldn't the view be aware of the concrete way to get the user's data? But how can I separate the controller from the view then? Is it possible to make both completely independent of each other as their purposes suggest?

Example: When I have an application which uses the curses library for the view it implies that the it's only accessible through the terminal. Using curses methods to read user data in the controller would break encapsulation but calling methods on the view would have nothing to do with displaying the model.

+1  A: 

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

Mitch Wheat
A: 

Consider having the View and Controller communicate through the Observer pattern. The Controller registers itself as an Observer with the View. When the user inputs data into the View and presses Enter, then the View interprets the data and notifies its observers that there is data available. The Controller can then get the data from the View through a public method.

Nick Meyer
A: 

I think the view should have a callback on the controller to send over user input. In web architecture, the callback is provided through the ability to send the user input back to the server through http requests.

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

Jean
+1  A: 

I dont think that the view really has much to do with inputting data actually. I find MVC much easier to visualise if you see the user as communicating with the controller directly. A controller receives data from the user and sends views back. In many systems the view engine has some limited way of updating itself (ie text inputs display what is typed before it is sent to the controller). But for any MVC type architecture you can replace any view with any other view provided they are both capable of handling the same data.

For example. Entering a username can be done on any system that supports entering strings. The controller accepts a string, and so can be used in a web application, a terminal application, or a GUI application.

Jack Ryan
A: 

Well,

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

MVC -> Model View Controler

There are many implementation of MVC, I don't know your case, but I'll give you one.

The most common MVC implementation acts like this..

view <-> Controler <-> Model

In a web scenario..

The view would be your HTML pages and data input would happen in a form.

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

Home would be your controller (a class named home), and createuser a method in home.

public class Home extends Controller {

   public void createUser(Userform f){
      ...create user...
   }
}

This form would submit data into the method as parameters. Createuser would them processed to talk to the model and later persist the data if thats the case.