SlideShare a Scribd company logo
It’s Just a View
An Introduction to
model view controller
Aaron Nordyke, Sr. Software Engineer
Separation of
Concerns
Spaghetti Code

           UGLY
      g

          the
There once was
a drug named

Xigris…
Xigris                Xigris

           Xigris                         Xigris

            Xigris
 Xigris
                                 Xigris


            Xigris
                                 Xigris
 Xigris


               Xigris                       Xigris
Xigris
Modules

       GOOD
     th e
Two
Engineers
Made a bet
Maximize
Developer Sanity
MVC
      BADASS
 g

     the
DATA   DOM
Controller
                View to Model
                 Interaction
                One Direction




      View                             Model
 User Interaction                 Data
 HTML                             Business Logic
                                   DB Interaction
                      Observer
                      Pattern
2   View alerts
                              Controller              Controller Updates Model
    controller of                                 3
    particular
    event




                     4   Model alerts view that
                         it has changed.
            View                                           Model




                                 5   View grabs model data
1   User interacts                   and updates itself.
    with a view
2   View alerts
                      Controller              Controller Updates Model
    controller of                         3
    particular
    event




             View 1                                 Model
                       4 Model alerts
                           view that it has
                           changed.

1 User interacts
    with a view
                              View 2          5   View grabs model data
                                                  and updates itself.
Controller
                View to Model
                 Interaction
                One Direction




      View                             Model
 User Interaction                 Data
 HTML                             Business Logic
                                   DB Interaction
                      Observer
                      Pattern
Percentage of Code

                Views
     Models



              Controllers
The page is not the view



         View
The page contains the views
                      View          View
               View
                      View          View
 View                 View          View
                      View          View
               View
                             View
 View

        View          View
MVC’s Bestest Friends


Observer Pattern   Templating Library
          MVC Framework
Best Friend #1

Observer
                 Pattern
Controller
                View-Model
                 Interaction
                One Direction




      View                             Model
 User Interaction                 Data
 HTML                             Business Logic
                                   DB Interaction
                      Observer
                      Pattern
Lame Real-world Analogy
           1   “If little Billy gets hurt,
               I want you to call this
               number immediately.”


  Mother                                     Babysitter



           2   Little Billy breaks his
               arm while ice-skating,
               so babysitter calls the
               supplied number.
Observer and Subject
           1   “If this thing I care
               about happens,
               call this function.”


Observer                               Subject


           2   The things happens,
               so the subject calls
               the function.
Observer   Observer   Observer




Observer   Subject    Observer




Observer   Observer   Observer
View-Model Relationship
                 1   “If this certain data
                     changes, call my
                     function view.foo().

      View                                    Model
    (Observer)                               (Subject)



2   The change happens,        3   The view grabs the
    so the model calls             changed data from the
    view.foo().                    model and updates
                                   itself.
Observer Pattern – Basic Use
 3   view.prototype.render = function(){
         //grab model data and update view html
     }

     /*
      * view tells model that if “change” happens,
      * then call view’s render function
      */
 1   model.subscribe(“change”,view.render);


     /*
      * The “change” happens, so the model alerts
      * any observers of “change”
      */
 2   model.notify(“change”);
Observer Pattern -- Internals
var events = [

     {“abitraryString1” : [function1, function2] },

     //model.notify(“arbitraryString2”) would
     //cause function2 and function3 to be called.
     {“abritraryString2” : [function2, function3] },

     //model.subscribe(“arbitraryString3”,function4)
     //would add function4 to this list
     {“abritraryString3” : [function3] },

     //model.subscribe(“arbitraryString4”,function1)
     //would add a new member to the events array
];
Best Friend #2
{{Templating}}
      Library
Look Familiar?
var container = Util.cep("div",{
    "className":"wrap",
});

var firstName = Util.cep("span",{
   "className":"name",
   "innerHTML":person.firstName
});

var lastName = Util.cep("span",{
   "className":"name",
   "innerHTML":person.lastName
});

Util.ac(firstName,container);
Util.ac(lastName,container);
Replaced with {{Templates}}
//template
<div class="wrap">
  <span class="name">{{firstName}}</span>
  <span class="name">{{lastName}}</span>
</div>



var html = Mustache.to_html(template,person)
Popular Templates



}
mustache.js
    Logic-less templates      Minimal Templating on Steroids
http://mustache.github.com/    http://www.handlebarsjs.com/
Best Friend #3



Framework
Sole focus
Help you do MVC
• Classes for the separate concerns of
    Models, Views, and Controllers
•   Observer Pattern built-in
•   Templating built-in
•   Event Delegation built-in
•   Small -- 4.6kb, compressed
“It's all too easy to create
JavaScript applications that end
up as tangled piles of jQuery
selectors and callbacks, all trying
frantically to keep data in sync
between the HTML UI, your
JavaScript logic, and the database
on your server.”
        Jeremy Ashkenas, Creator of Backbone.js
SUMMARY
Separation of concerns
Model-View-Controller
Friends of MVC

More Related Content

What's hot

Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
M Ahsan Khan
 
MVC Architecture
MVC ArchitectureMVC Architecture
What is MVC?
What is MVC?What is MVC?
What is MVC?
Dominique Cimafranca
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
ravindraquicsolv
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
Emily Bauman
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
icapetillos
 
Principles of MVC for Rails Developers
Principles of MVC for Rails DevelopersPrinciples of MVC for Rails Developers
Principles of MVC for Rails Developers
Edureka!
 
MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
Prem Sanil
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
Ni
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
Surbhi Panhalkar
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
Wayne Tun Myint
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
Dipika Wadhvani
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
Volkan Uzun
 
MVC architecture by Mohd.Awais on 18th Aug, 2017
MVC architecture by Mohd.Awais on 18th Aug, 2017MVC architecture by Mohd.Awais on 18th Aug, 2017
MVC architecture by Mohd.Awais on 18th Aug, 2017
Innovation Studio
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
vamsitricks
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
Nguyễn Thành Phát
 
MVC
MVCMVC
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
Anton Krasnoshchok
 
MVC Seminar Presantation
MVC Seminar PresantationMVC Seminar Presantation
MVC Seminar Presantation
Abhishek Yadav
 
MSDN - ASP.NET MVC
MSDN - ASP.NET MVCMSDN - ASP.NET MVC
MSDN - ASP.NET MVC
Maarten Balliauw
 

What's hot (20)

Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
 
What is MVC?
What is MVC?What is MVC?
What is MVC?
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
Principles of MVC for Rails Developers
Principles of MVC for Rails DevelopersPrinciples of MVC for Rails Developers
Principles of MVC for Rails Developers
 
MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
MVC architecture by Mohd.Awais on 18th Aug, 2017
MVC architecture by Mohd.Awais on 18th Aug, 2017MVC architecture by Mohd.Awais on 18th Aug, 2017
MVC architecture by Mohd.Awais on 18th Aug, 2017
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
 
MVC
MVCMVC
MVC
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
MVC Seminar Presantation
MVC Seminar PresantationMVC Seminar Presantation
MVC Seminar Presantation
 
MSDN - ASP.NET MVC
MSDN - ASP.NET MVCMSDN - ASP.NET MVC
MSDN - ASP.NET MVC
 

Similar to Just a View: An Introduction To Model-View-Controller Pattern

The MVVM Pattern
The MVVM PatternThe MVVM Pattern
The MVVM Pattern
Chris Charabaruk
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
Jonathan Engelsma
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-Binder
Simon Massey
 
ReactJS Overview
ReactJS OverviewReactJS Overview
ReactJS Overview
Ping-Wen (Mark) Hsu
 
Applied MVVM in Windows 8 apps: not your typical MVVM session!
Applied MVVM in Windows 8 apps: not your typical MVVM session!Applied MVVM in Windows 8 apps: not your typical MVVM session!
Applied MVVM in Windows 8 apps: not your typical MVVM session!
Microsoft Developer Network (MSDN) - Belgium and Luxembourg
 
Class 02 Objective C
Class 02   Objective CClass 02   Objective C
Class 02 Objective C
Violeta Salas
 
Onlineshopping
OnlineshoppingOnlineshopping
Onlineshopping
amitesh2690
 
Design patterns
Design patternsDesign patterns
Design patterns
mudabbirwarsi
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10
Bryan Anderson
 
Eclipse MVC
Eclipse MVCEclipse MVC
Eclipse MVC
Zoltán Mátyás
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Jinkyu Kim
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
Anuradha Bandara
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web development
Volodymyr Voytyshyn
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
Abhishek Sur
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
Abhishek Sur
 
iOS Design Patterns
iOS Design PatternsiOS Design Patterns
iOS Design Patterns
Andreas Blick
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
Jay Kumarr
 
Joomla Complex Component MVC Proposal
Joomla Complex Component MVC ProposalJoomla Complex Component MVC Proposal
Joomla Complex Component MVC Proposal
Júlio Pontes
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
Dong-Ho Lee
 
Design patterns difference between interview questions
Design patterns   difference between interview questionsDesign patterns   difference between interview questions
Design patterns difference between interview questions
Umar Ali
 

Similar to Just a View: An Introduction To Model-View-Controller Pattern (20)

The MVVM Pattern
The MVVM PatternThe MVVM Pattern
The MVVM Pattern
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-Binder
 
ReactJS Overview
ReactJS OverviewReactJS Overview
ReactJS Overview
 
Applied MVVM in Windows 8 apps: not your typical MVVM session!
Applied MVVM in Windows 8 apps: not your typical MVVM session!Applied MVVM in Windows 8 apps: not your typical MVVM session!
Applied MVVM in Windows 8 apps: not your typical MVVM session!
 
Class 02 Objective C
Class 02   Objective CClass 02   Objective C
Class 02 Objective C
 
Onlineshopping
OnlineshoppingOnlineshopping
Onlineshopping
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10
 
Eclipse MVC
Eclipse MVCEclipse MVC
Eclipse MVC
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 
ASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web developmentASP.NET MVC as the next step in web development
ASP.NET MVC as the next step in web development
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
 
iOS Design Patterns
iOS Design PatternsiOS Design Patterns
iOS Design Patterns
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
 
Joomla Complex Component MVC Proposal
Joomla Complex Component MVC ProposalJoomla Complex Component MVC Proposal
Joomla Complex Component MVC Proposal
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
 
Design patterns difference between interview questions
Design patterns   difference between interview questionsDesign patterns   difference between interview questions
Design patterns difference between interview questions
 

Recently uploaded

Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 

Recently uploaded (20)

Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 

Just a View: An Introduction To Model-View-Controller Pattern

  • 1. It’s Just a View An Introduction to model view controller Aaron Nordyke, Sr. Software Engineer
  • 3. Spaghetti Code UGLY g the
  • 4. There once was a drug named Xigris…
  • 5. Xigris Xigris Xigris Xigris Xigris Xigris Xigris Xigris Xigris Xigris Xigris Xigris Xigris
  • 6. Modules GOOD th e
  • 8.
  • 10. MVC BADASS g the
  • 11. DATA DOM
  • 12. Controller  View to Model Interaction  One Direction View Model  User Interaction  Data  HTML  Business Logic  DB Interaction Observer Pattern
  • 13. 2 View alerts Controller Controller Updates Model controller of 3 particular event 4 Model alerts view that it has changed. View Model 5 View grabs model data 1 User interacts and updates itself. with a view
  • 14. 2 View alerts Controller Controller Updates Model controller of 3 particular event View 1 Model 4 Model alerts view that it has changed. 1 User interacts with a view View 2 5 View grabs model data and updates itself.
  • 15. Controller  View to Model Interaction  One Direction View Model  User Interaction  Data  HTML  Business Logic  DB Interaction Observer Pattern
  • 16. Percentage of Code Views Models Controllers
  • 17. The page is not the view View
  • 18. The page contains the views View View View View View View View View View View View View View View View
  • 19. MVC’s Bestest Friends Observer Pattern Templating Library MVC Framework
  • 21. Controller  View-Model Interaction  One Direction View Model  User Interaction  Data  HTML  Business Logic  DB Interaction Observer Pattern
  • 22. Lame Real-world Analogy 1 “If little Billy gets hurt, I want you to call this number immediately.” Mother Babysitter 2 Little Billy breaks his arm while ice-skating, so babysitter calls the supplied number.
  • 23. Observer and Subject 1 “If this thing I care about happens, call this function.” Observer Subject 2 The things happens, so the subject calls the function.
  • 24. Observer Observer Observer Observer Subject Observer Observer Observer Observer
  • 25. View-Model Relationship 1 “If this certain data changes, call my function view.foo(). View Model (Observer) (Subject) 2 The change happens, 3 The view grabs the so the model calls changed data from the view.foo(). model and updates itself.
  • 26. Observer Pattern – Basic Use 3 view.prototype.render = function(){ //grab model data and update view html } /* * view tells model that if “change” happens, * then call view’s render function */ 1 model.subscribe(“change”,view.render); /* * The “change” happens, so the model alerts * any observers of “change” */ 2 model.notify(“change”);
  • 27. Observer Pattern -- Internals var events = [ {“abitraryString1” : [function1, function2] }, //model.notify(“arbitraryString2”) would //cause function2 and function3 to be called. {“abritraryString2” : [function2, function3] }, //model.subscribe(“arbitraryString3”,function4) //would add function4 to this list {“abritraryString3” : [function3] }, //model.subscribe(“arbitraryString4”,function1) //would add a new member to the events array ];
  • 29. Look Familiar? var container = Util.cep("div",{ "className":"wrap", }); var firstName = Util.cep("span",{ "className":"name", "innerHTML":person.firstName }); var lastName = Util.cep("span",{ "className":"name", "innerHTML":person.lastName }); Util.ac(firstName,container); Util.ac(lastName,container);
  • 30. Replaced with {{Templates}} //template <div class="wrap"> <span class="name">{{firstName}}</span> <span class="name">{{lastName}}</span> </div> var html = Mustache.to_html(template,person)
  • 31. Popular Templates } mustache.js Logic-less templates Minimal Templating on Steroids http://mustache.github.com/ http://www.handlebarsjs.com/
  • 34. • Classes for the separate concerns of Models, Views, and Controllers • Observer Pattern built-in • Templating built-in • Event Delegation built-in • Small -- 4.6kb, compressed
  • 35. “It's all too easy to create JavaScript applications that end up as tangled piles of jQuery selectors and callbacks, all trying frantically to keep data in sync between the HTML UI, your JavaScript logic, and the database on your server.” Jeremy Ashkenas, Creator of Backbone.js