MVC Architecture

<p>A set of patterns and concepts that define the main <b>divisions</b> of your application, their responsibilities, and how they should work together.</p>
<p>A blueprint for the overall structure of your application that dictates how responsibilities should be delegated, and outlines a pattern of <b>communication</b><br />between each working part.</p>
<h3>Mental Model</h3>
  <li>makes abstract concepts more tangible</li>
  <li>app logic is easier to reason about when it's grouped under an 'umbrella' term</li>
<h3>Separation of Concerns & Modularity</h3>
  <li>adds flexibility & durability for rapid iterations</li>
  <li>makes it easier to reuse code</li>
  <li>promotes efficient collaboration</li>
  <li>can anticipate how an app will work and where it might break</li>
  <li>allows us to build frameworks to solve common problems</li>
<h2>Different Schools of Thought</h2>
<p>[ models - operations - views - events ]</p>
<p>[ models - views - presenters ]</p>
<p>[models - views - controllers ]</p>
<h2>MVC Breakdown:</h2>
<h3>The divisions</h3>
<p>[ models - views - controllers ]</p>
<p>Define and structure what data the application should contain</p>
<br />
<p><i>i.e. grocery object, list of groceries</i></p>
<p>Define how the application data should be displayed; the visual representation of the model</p>
<br />
<p><i>i.e. UI of grocery app, buttons, list elements, etc</i></p>
<p>Dictates how a model or view should be updated in response to user input; the link between a user and the system</p>
<br />
<p><i>i.e. click on button to add a grocery, update the grocery list in state</i></p>
<h2>MVC Example: The Browser</h2>
<p>HTML = Model</p>
<img src="../../assets/images/lessons/mvc-architecture/model.png" />
<p>CSS = View</p>
<img src="../../assets/images/lessons/mvc-architecture/view.png" />
<p>Browser = Controller</p>
<img src="../../assets/images/lessons/mvc-architecture/controller.png" />


<h2>MVC Breakdown:</h2>
<h3>Communication</h3>   <img src="../../assets/images/lessons/mvc-architecture/communication.png" />

Modern Front-End Frameworks

  • Backbone.Js
  • Angularjs
  • Ember.Js
  • ReactJS*

Why use a framework?

  • Forces you to reap the benefits of the MVC design pattern
  • Makes apps easier to test
  • Learning a new framework is hard...but solving the problems that frameworks handle for us is harder
<h2>Life without Frameworks</h2>
<h2>Data Binding & Templating: before</h2>
  <code class="javascript js">
  &lt;input type="text" class="current-grocery" /&gt;
  &lt;div id="grocery-name"&gt;&lt;/div&gt;

  $('input.current-grocery').on('keyup', (e) => {
    $('#grocery-name').text(`Current Word: ${this.val()}`);
<h2>Data Binding & Templating: after</h2>
  <code class="html">
<input type="text" onChange={this.handleChange()} />
Current Grocery: {this.state.currentGrocery}
<h2>Routing: before</h2>
<h2>Routing: after</h2>
  <code class="javascript js">   &lt;Router&gt;
&lt;Route path="/" component={App}&gt;
  &lt;Route path="groceries/" component={GroceryList} /&gt;
  &lt;Route path="groceries/:id" component={GroceryDetail} /&gt;
&lt;/Route&gt;   &lt;/Router&gt;
<h2>Communication: before</h2>
<h2>Communication: after</h2>
  <code class="javascript">
  // Model
  const groceryStore = {
    groceries: [],
    currentGrocery: null

  // View
  <input type="text" onChange={this.handleChange(e)} />
  Current Grocery: {this.state.currentGrocery}

  // Controller Functions
  handleChange(e) => {

  groceryChanged(grocery => {
    type: 'GROCERY_CHANGED', // action

  case GROCERY_CHANGED: // reducer
    return Object.assign({}, state, {
<h2>The Frameworks</h2>
<h2><a href="">Backbone.js</a></h2>
  <li>Small and lightweight</li>
  <li>Many 3rd-party libraries built on top</li>
  <li><b>MVC Implementation:</b> Models/Collections - Views - Routes</li>
<h2><a href="">Angular</a></h2>
  <li>Larger framework, gives you a lot for free</li>
  <li>Very flexible despite its size - a "framework to build a framework"</li>
  <li><b>MVC Implementation:</b> Angular Data - Components - Directives</li>
<h2><a href="">Ember</a></h2>
  <li>Larger framework, gives you a lot for free</li>
  <li>Favors convention over configuration - much more opinionated, less flexible</li>
  <li><b>MVC Implementation:</b> Ember Data - Components - Services</li>
<h2><a href="">React</a></h2>
  <li>Considered to be more of a library than a framework</li>
  <li>Often described as "just the view layer" of MVC</li>
  <li><b>MVC Implementation:</b> Redux Store - React Components - Actions/Reducers</li>

Choosing a Framework

  • big vs. small: how complex is your application?
  • flexible vs. opinionated: how much control do you want?
  • community & support: can you get help when needed?

todomvc: compare setup & syntax