Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat goes into the "Controller" in "MVC"?
    text
    copied!<p>I think I understand the basic concepts of MVC - the Model contains the data and behaviour of the application, the View is responsible for displaying it to the user and the Controller deals with user input. What I'm uncertain about is exactly <em>what</em> goes in the Controller.</p> <p>Lets say for example I have a fairly simple application (I'm specifically thinking Java, but I suppose the same principles apply elsewhere). I organise my code into 3 packages called <code>app.model</code>, <code>app.view</code> and <code>app.controller</code>.</p> <p>Within the <code>app.model</code> package, I have a few classes that reflect the actual behaviour of the application. These <code>extends Observable</code> and use <code>setChanged()</code> and <code>notifyObservers()</code> to trigger the views to update when appropriate.</p> <p>The <code>app.view</code> package has a class (or several classes for different types of display) that uses <code>javax.swing</code> components to handle the display. Some of these components need to feed back into the Model. If I understand correctly, the View shouldn't have anything to do with the feedback - that should be dealt with by the Controller.</p> <p>So what do I actually put in the Controller? Do I put the <code>public void actionPerformed(ActionEvent e)</code> in the View with just a call to a method in the Controller? If so, should any validation etc be done in the Controller? If so, how do I feedback error messages back to the View - should that go through the Model again, or should the Controller just send it straight back to View?</p> <p>If the validation is done in the View, what do I put in the Controller?</p> <p>Sorry for the long question, I just wanted to document my understanding of the process and hopefully someone can clarify this issue for me!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload