Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does an MVC system work?
    text
    copied!<p>I'm trying to learn the MVC pattern, but each place say something different. So now I don't know whats the true MVC.</p> <p>So I'm guessing its the most pure MVC:</p> <ul> <li><strong>Model</strong> is <strong>just data</strong> and notify data changes.</li> <li><strong>View</strong> reads the messages of the <strong>Model</strong> to update the view.</li> <li><strong>Controller</strong> reads the user input from <strong>View</strong> and changes the Model according.</li> </ul> <p><strong>Implementing</strong></p> <ul> <li><strong>Model</strong> knows no one.</li> <li><strong>View</strong> knows the <strong>Model</strong>.</li> <li><strong>Controller</strong> knows both <strong>View</strong> and <strong>Model</strong>.</li> </ul> <p>Pseudocode:</p> <pre><code>/* Model */ class Color{ color = blue; setColor(color); notifyUpdate(); } /* View */ class ColorPicker(model){ model.register(update); update(){ this.colorToExhibit = model.color; } } /* Controller */ class Colorize(view, model){ view.register(update); update(color){ model.setColor(color); } } </code></pre> <p>Some questions:</p> <ol> <li>Is that right?</li> <li>I can't see why the <strong>View</strong> cannot change the <strong>Model</strong> directly, but through Controller.</li> <li>Suppose I have animations to be performed after an action. Who must handle this animation: the Model, the View, or the Controller? Also: the animation logic is part of the Model, View, or Controller? More: Suppose a Poker game. After the user choose an action (say, 'Raise'), the system must play an animation (say, the chips going from player spot to the desk). How can I see this poker example (with animation) as a MVC? Can you explain and give a pseudocode about that?</li> </ol> <p>Thank you.</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