Slide 1

Slide 1 text

50 Shades of MVC

Slide 2

Slide 2 text

Pablo Astigarraga

Slide 3

Slide 3 text

! @poteland github.com/pote

Slide 4

Slide 4 text

tarmac.io

Slide 5

Slide 5 text

Surculus Fructum

Slide 6

Slide 6 text

Uruguay

Slide 7

Slide 7 text

Uruguay

Slide 8

Slide 8 text

Argentina

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

! Thank you RubyConf Ar <3

Slide 11

Slide 11 text

Model View Controller

Slide 12

Slide 12 text

2004 - 2005

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Models Data + Behavior

Slide 15

Slide 15 text

Views User Interface !

Slide 16

Slide 16 text

Controllers Glue. (?)

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Browser GET / HTTP/1.1

Slide 19

Slide 19 text

Web Server

Slide 20

Slide 20 text

Router MyApp::Application.routes.draw do! get '/' => 'sessions#new'! root :to => 'sessions#new' ! end!

Slide 21

Slide 21 text

Router MyApp::Application.routes.draw do! get '/' => 'sessions#new'! root :to => 'sessions#new' ! end!

Slide 22

Slide 22 text

Router MyApp::Application.routes.draw do! get '/' => 'sessions#new'! root :to => 'sessions#new' ! end!

Slide 23

Slide 23 text

Controller class SessionsController < ApplicationController! def new! @model = FictionalModel.last! render :new! end! end!

Slide 24

Slide 24 text

Model class FictionalModel < ActiveRecord::Base! # validations! # other stuff (?)! end!

Slide 25

Slide 25 text

Database SELECT * FROM fictional_models ORDER BY fictional_models.id DESC LIMIT 1

Slide 26

Slide 26 text

Model # => #

Slide 27

Slide 27 text

Controller class SessionsController < ApplicationController! def new! @model = FictionalModel.last! render :new! end! end!

Slide 28

Slide 28 text

Controller class SessionsController < ApplicationController! def new! @model = FictionalModel.last! render :new! end! end!

Slide 29

Slide 29 text

View
!

! Our last registeded model is: <%= @model.name %>!

! ! Sign in with Google!
!

Slide 30

Slide 30 text

Browser
!

! Our last registeded model is: Derek Zoolander!

! ! Sign in with Google!
!

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

What about Logic?

Slide 33

Slide 33 text

Logic in Views? (›°□°)›ớ sʍǝıᴧ

Slide 34

Slide 34 text

Logic in Controllers? (›°□°)›ớ sɹǝʃʃoɹʇuoↃ

Slide 35

Slide 35 text

Logic in Controllers? Controllers ϊ( ʄ-ʄϊ)

Slide 36

Slide 36 text

Logic in Models? ¯\_(π)_/¯

Slide 37

Slide 37 text

ಠ_ಠ

Slide 38

Slide 38 text

?

Slide 39

Slide 39 text

ಠ_ಠ

Slide 40

Slide 40 text

197x - 1988

Slide 41

Slide 41 text

“Everything is an Object”

Slide 42

Slide 42 text

Smalltalk

Slide 43

Slide 43 text

Xerox PARC

Slide 44

Slide 44 text

Message Passing

Slide 45

Slide 45 text

Integrated Development Environment

Slide 46

Slide 46 text

Inspired:

Slide 47

Slide 47 text

Graphical Interfaces (pretty much)

Slide 48

Slide 48 text

Graphical Interfaces are why MVC exists.

Slide 49

Slide 49 text

MVC in Smalltalk

Slide 50

Slide 50 text

Interactions

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Controller Sends commands to its associated view to change the view's presentation ! Sends commands to the model to update the model's state

Slide 53

Slide 53 text

View Requests from the model the information that it needs to generate an output representation to the user.

Slide 54

Slide 54 text

Model Notifies its associated views and controllers when there has been a change in its state.

Slide 55

Slide 55 text

Model A passive implementation of MVC omits these notifications, because the application does not require them or the software platform does not support them

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

“Thin Client”

Slide 58

Slide 58 text

We can do this.

Slide 59

Slide 59 text

Websockets

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

“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!

Slide 62

Slide 62 text

class Timeline < ActiveRecord::Base! ! after_save :notify_views! ! def websockets_channel! "#{ self.class } #{ self.id }".hash! “Active” MVC.

Slide 63

Slide 63 text

“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,

Slide 64

Slide 64 text

class Timeline < ActiveRecord::B ! after_save :notify_views! ! def websockets_channel! "#{ self.class }#{ self.id } end! ! “Active” MVC.

Slide 65

Slide 65 text

“Active” MVC. end! ! private! ! def notify_views! Pusher.trigger(! self.websockets_channel,! 'update',! { self: self.to_json }! )! end! end!

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

GET /timelines/1 http http

Slide 68

Slide 68 text

PUT /timelines/1 http

Slide 69

Slide 69 text

Web Server

Slide 70

Slide 70 text

Router MyApp::Application.routes.draw do! get '/' => 'sessions#new'! root :to => 'sessions#new' ! end!

Slide 71

Slide 71 text

Controller class TimelinesController < ApplicationController! def update! @timeline = Timeline.find(params[:id])! if @timeline.update_attributes(params[:timeline])! #...! #...! end! end!

Slide 72

Slide 72 text

Model after_save :notify_views

Slide 73

Slide 73 text

Model def notify_views! Pusher.trigger(! self.websockets_channel,! 'update',! { self: self.to_json }! )! end!

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Websockets <3

Slide 78

Slide 78 text

(Never said it was a good idea)

Slide 79

Slide 79 text

2009 - 2013

Slide 80

Slide 80 text

JavaScript

Slide 81

Slide 81 text

MVC in the browser.

Slide 82

Slide 82 text

Full Circle.

Slide 83

Slide 83 text

View Requests from the model the information that it needs to generate an output representation to the user.

Slide 84

Slide 84 text

Empower your Views

Slide 85

Slide 85 text

Backbone.js

Slide 86

Slide 86 text

Angular.js

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

So what is MVC’s purpose?

Slide 89

Slide 89 text

Separation of Concerns ! (for graphical interface apps)

Slide 90

Slide 90 text

Guideline.

Slide 91

Slide 91 text

Tailor MVC to your needs.

Slide 92

Slide 92 text

You > MVC

Slide 93

Slide 93 text

Gracias! @poteland

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

Questions? @poteland References: