Upgrade to Pro — share decks privately, control downloads, hide ads and more …

50 Shades of MVC

50 Shades of MVC

Video: https://vimeo.com/89377195

We at the Rails world are very proud of embracing the Model-View-Controller design pattern, it is integral to the way we build web applications and there is a general consensus that all of us generally know what we are talking about in regards to it, hell , most of our code files are under a model, controller or views directories! We've got to know what we are doing, right?

Much like Object Orientation the Model-View-Controller pattern is one of the most popular-yet-heavily-altered concepts in modern computer science, what were the original propositions of the pattern? How was it applied back in the 70's, when it was proposed as a part of Smalltalk? How much have we changed it to adapt it to the web application scene? How can we apply this to our day to day work in 2013? is altering the original pattern necessarily a bad thing?

On this talk I present different aspects of the MVC pattern and its changes from its inception to modern day use, what to keep in mind about the pattern as opposed to a single framework's implementation of it and how knowing this should make us all around better programmers.

Pablo Astigarraga

June 07, 2013
Tweet

More Decks by Pablo Astigarraga

Other Decks in Programming

Transcript

  1. View <div id="sign_in">! <h3>! Our last registeded model is: <%=

    @model.name %>! </h3>! ! <a href="/auth/google">Sign in with Google</a>! <div>!
  2. Browser <div id="sign_in">! <h3>! Our last registeded model is: Derek

    Zoolander! </h3>! ! <a href="/auth/google">Sign in with Google</a>! <div>!
  3. ?

  4. Controller Sends commands to its associated view to change the

    view's presentation ! Sends commands to the model to update the model's state
  5. View Requests from the model the information that it needs

    to generate an output representation to the user.
  6. Model A passive implementation of MVC omits these notifications, because

    the application does not require them or the software platform does not support them
  7. “Active” MVC. class Timeline < ActiveRecord::Base! ! after_save :notify_views! !

    def websockets_channel! "#{ self.class }#{ self.id }".hash! end! ! private! ! def notify_views! Pusher.trigger(self.websockets_channel, 'update', { self: self.to_json })! end! end!
  8. “Active” MVC. class Timeline < ActiveRecord::Base! ! after_save :notify_views! !

    def websockets_channel! "#{ self.class }#{ self.id }".hash! end! ! private! ! def notify_views! Pusher.trigger(self.websockets_channel,
  9. View Requests from the model the information that it needs

    to generate an output representation to the user.