0

MVC stands for model, view and controller. Backbonejs.or explains this by comparison to Rails, more here and below. Because I don't know Rails, the comparison is quite meaningless. The exctract below highlight the controller, perhaps a reason not strictly an MVC -- not sure what it infers. What does it mean that Backbone is not a strict MVC?

Extract from the Backbonejs.org -site (source here).

How does Backbone relate to "traditional" MVC?

Different implementations of the Model-View-Controller pattern tend to disagree about the definition of a controller. If it helps any, in Backbone, the View class can also be thought of as a kind of controller, dispatching events that originate from the UI, with the HTML template serving as the true view. We call it a View because it represents a logical chunk of UI, responsible for the contents of a single DOM element.

Comparing the overall structure of Backbone to a server-side MVC framework like Rails, the pieces line up like so:

  • Backbone.Model – Like a Rails model minus the class methods. Wraps a row of data in business logic.
  • Backbone.Collection – A group of models on the client-side, with sorting/filtering/aggregation logic.
  • Backbone.Router – Rails routes.rb + Rails controller actions. Maps URLs to functions.
  • Backbone.View – A logical, re-usable piece of UI. Often, but not always, associated with a model.
  • Client-side Templates – Rails .html.erb views, rendering a chunk of HTML.

I added the italics to highlight the point why it is not apparently a MVC. Above I can find the model and view -terms -- but the term controller is left out explicitly, instead using terms router, collection and templates. Why are router/collection/templates not a controller?

I find this controller -definition, controller mediates input, converting it to commands for the model or view (Wikipeadia here), a bit fuzzy.

Community
  • 1
  • 1
hhh
  • 50,788
  • 62
  • 179
  • 282
  • Quite popular thread about MVC [here](http://stackoverflow.com/questions/5863870/how-should-a-model-be-structured-in-mvc/5864000#5864000). – hhh Jul 31 '12 at 09:18

2 Answers2

2

Pretty funny statement, especially since Rails are quite far from implementation of MVC-inspired design pattern. Actually, I would say, that BackboneJS's interpretation is much closer to MVC ideas.

The view is not supposed to be just a dumb template. It should be responsible for all the presentation logic (and, in the case of classical MVC, Model2 MVC and HMVC patterns, an active structure).

What the Rails framework implements could be better described as "ORM, Template, Adapter" antipattern, where both business and presentation logic is being forced into what they call "controller".

What the BackboneJS implements is actually closer to MVVM design pattern, where viewmodel is providing passive view with information. Then view decides what to do with it and which templates to employ.

tereško
  • 58,060
  • 25
  • 98
  • 150
0

As I understand it, a traditional MVC pattern has the following elements:

Model - holds data only (maybe some data-processing methods)

View - renders visual and interactive elements that exhibit parts of the data to users.

Controller - handles interactions between models and views and between the user and the code (e.g., when model updates, re-render a view, when user clicks a button, change the data in the model).

In Backbone, there is no explicit controller. Instead, this control function is performed by: a) the Views themselves (e.g., setting event listeners to update models on user actions) b) Routers that handle which views to display and c) the index file or other HTML / JS code.

lubar
  • 2,589
  • 2
  • 26
  • 28
  • You really do not understand, what are the responsibilities of model layer. Or what the controllers are supposed to do. – tereško Jul 31 '12 at 01:07
  • I am confused -- you meaning something like this [here](http://i.stack.imgur.com/brjhk.png) from the thread [here](http://stackoverflow.com/questions/5863870/how-should-a-model-be-structured-in-mvc/5864000#5864000). MVC originally designed for GUI: `"MVC was originally developed to map the traditional input, processing, output roles into the GUI realm:"` (source latter thread)?! – hhh Jul 31 '12 at 09:48