SlideShare une entreprise Scribd logo
1  sur  32
R
A Presentation by: Ravi Bhadauria
ISO 9001 : 2008 CERTIFIED
Learn JavaScript, jQuery, AngularJS from Expert in
ADMEC MULTIMEDIA INSTITUTE
www.admecindia.co.in | www.graphic-design-institute.com
Phones: +91-9811-8181-22, +91-9911-7823-50
MVC Design Pattern in JavaScript
MVC in JavaScript: A Practical Explanation
● MVC Introduction
– What is MVC?
– What is M in MVC?
– What is V in MVC?
– What is C in MVC?
● Use of MVC in an Application
– Planning for an MVC Application
– Writing code for Model
– Writing code for View
– Writing code for Controller
● Testing and Debugging
– Useful tools
– Validating the code
By: Ravi Bhadauria
Date: 22-01-2016
Purpose: Lecture
Preface & Acknowledgment
Dear reader,
ADMEC Multimedia Institute is a growing institute that is providing industry oriented
training in web design and web development along with multimedia, animation, graphic
design, cad etc to the world at large.
This presentation is one of the best presentations from our study material for our
JavaScript Object Oriented workshops which ADMEC conducts every week at the
center. We have planned to share it with the world so that everyone can take benefits
from our small efforts.
This presentation contains a brief information for “MVC Design Patterns in JavaScript”.
We express thanks to many books and websites for making it one of the best
presentations of all the time.
Thanks
Ravi Bhadauria, Instructor (Web UI and Back-end Development)
Profile: Director ADMEC Multimedia Institute
Url: http://www.admecindia.co.in
What is MVC?
Earlier I was working in ActionScript and PHP. I used to think that it is
only my favorite programming but when I started using JavaScript in
2006 then it changed my opinion.
Now JavaScript is my one of the best programming languages that I am
using for client side and server side requirements. The reason behind
that is its simplicity and scalability. Other programmings start buckling up
as they get bigger or larger while JavaScript provides an easy to use and
easy to understand manner in that situation.
MVC is a design pattern that provide design solution for JavaScript
programmers. MVC is not a JavaScript specific design patter; it is being
used by many languages as it is a best practice to code which is
scalable, flexible, modular, and easy to manage.
What is M letter in MVC?
M is one of the most important components of MVC. M
stands for Model.
Model is the domain-specific representation of the
information on which the application operates. Model
handles the business logic and database related
responsibilities. Domain logic adds meaning to raw data
(e.g. calculating if today is the user’s birthday, or the totals,
taxes and shipping charges for shopping cart items).
What is V letter in MVC?
V stands for View in MVC. It handles the presentation of the
web page or web application.
It fetches the data from model and renders that into a form
suitable for interaction, typically a user interface element.
MVC is often seen in web applications, where the view is the
HTML page and the code which gathers dynamic data for
the page.
What is C letter in MVC?
C is the last and very important component of MVC as it
controls the application logic and It is known as Controller.
It helps in processing and responding to events, typically
user actions, and invokes changes on the model and
perhaps the view.
How MVC Improves JavaScript?
What is a robust and successful application of JavaScript?
The answer is very simple:
“An application which has good features,
provides best performance, and scale well
when needed”
And I would say that MVC is the only rescue of such
applications in JavaScript to provide such features.
Creating an Application using MVC
I will show you how you can create a list of items which can
be manipulated using two buttons.
The data of the component is just a list of items, in which
one particular item can be selected and deleted. So, the
model of the component is very simple - it consists of an
array and a selected item index; and here it is on the next
slide.
Learn Advanced JavaScript from Experts
ADMEC MULTIMEDIA INSTITUTE
Leader in Animation & Digital Media Education
ISO 9001 : 2008 CERTIFIED
- Visit Our Websites -
www.admecindia.co.in
Phones: +91-9811-8181-22, +91-9911-7823-50
- Contact Us -
Planning for the UI in JavaScript
UI would be very simple with just 3 elements. You should
use Bootstrap's CSS and jQuery library for better results.
Implementing Observer Pattern - I
Event is a simple class for implementing the Observer pattern:
function Event(sender) {
this._sender = sender;
this._listeners = [];
}
Event.prototype = {
attach : function (listener) {
this._listeners.push(listener);
},
Implementing Observer Pattern - II
notify : function (args) {
var index;
for (index = 0; index < this._listeners.length; index += 1) {
this._listeners[index](this._sender, args);
}
}
};
Coding Model First - I
/**
* The Model. Model stores items and notifies
* observers about changes.
*/
function ListModel(items) {
this._items = items;
this._selectedIndex = -1;
this.itemAdded = new Event(this);
this.itemRemoved = new Event(this);
this.selectedIndexChanged = new Event(this);
}
Coding Model First - II
ListModel.prototype = {
getItems : function () {
return [].concat(this._items);
},
addItem : function (item) {
this._items.push(item);
this.itemAdded.notify({ item : item });
},
Coding Model First - III
removeItemAt : function (index) {
var item;
item = this._items[index];
this._items.splice(index, 1);
this.itemRemoved.notify({ item : item });
if (index === this._selectedIndex) {
this.setSelectedIndex(-1);
}
},
Coding Model First - IV
getSelectedIndex : function () {
return this._selectedIndex;
},
setSelectedIndex : function (index) {
var previousIndex;
previousIndex = this._selectedIndex;
this._selectedIndex = index;
this.selectedIndexChanged.notify({ previous : previousIndex });
}
};
Coding View then - I
/**
* The View. View presents the model and provides
* the UI events. The controller is attached to these
* events to handle the user interraction.
*/
function ListView(model, elements) {
this._model = model;
this._elements = elements;
this.listModified = new Event(this);
this.addButtonClicked = new Event(this);
this.delButtonClicked = new Event(this);
Coding View then - II
var _this = this;
// attach model listeners
this._model.itemAdded.attach(function () {
_this.rebuildList();
});
this._model.itemRemoved.attach(function () {
_this.rebuildList();
});
Coding View then - III
// attach listeners to HTML controls
this._elements.list.change(function (e) {
_this.listModified.notify({ index : e.target.selectedIndex });
});
this._elements.addButton.click(function () {
_this.addButtonClicked.notify();
});
this._elements.delButton.click(function () {
_this.delButtonClicked.notify();
});
}
Coding View then - IV
ListView.prototype = {
show : function () {
this.rebuildList();
},
rebuildList : function () {
var list, items, key;
list = this._elements.list;
list.html('');
Coding View then - V
items = this._model.getItems();
for (key in items) {
if (items.hasOwnProperty(key)) {
list.append($('<option>' + items[key] + '</option>'));
}
}
this._model.setSelectedIndex(-1);
}
};
Coding Controller Finally - I
/**
* The Controller. Controller responds to user actions and
* invokes changes on the model.
*/
function ListController(model, view) {
this._model = model;
this._view = view;
var _this = this;
Coding Controller Finally - II
this._view.listModified.attach(function (sender, args) {
_this.updateSelected(args.index);
});
this._view.addButtonClicked.attach(function () {
_this.addItem();
});
this._view.delButtonClicked.attach(function () {
_this.delItem();
});
}
Coding Controller Finally - III
ListController.prototype = {
addItem : function () {
var item = window.prompt('Add item:', '');
if (item) {
this._model.addItem(item);
}
},
delItem : function () {
var index;
Coding Controller Finally - IV
index = this._model.getSelectedIndex();
if (index !== -1) {
this._model.removeItemAt(this._model.getSelectedIndex());
}
},
updateSelected : function (index) {
this._model.setSelectedIndex(index);
}
};
The HTML
<div class="row container">
<div class="col-xs-4">
<select id="list" class="form-control" size="10"></select>
</div>
<div class="col-xs-8">
<button id="plusBtn" class="btn btn-default btn-block">+</button>
<button id="minusBtn" class="btn btn-default btn-block">-</button>
</div>
</div>
And I hope you didn't forget add Bootstrap CSS, jQuery Library, and MVC
JavaScript file which we created recently.
Clubbing up all
And of course, the Model, View, and Controller classes should be instantiated. The
sample, which you can below, uses the following code to instantiate and configure the
classes. You should put this code inside the html page just before closing body.
$(function () {
var model = new ListModel(['PHP', 'ActionScript', 'JavaScript']),
view = new ListView(model, {
'list' : $('#list'),
'addButton' : $('#plusBtn'),
'delButton' : $('#minusBtn')
}),
controller = new ListController(model, view);
view.show();
});​
Testing MVC Application in JavaScript
Open your html page in any of the browser and test. I am sure
you will have some lists inside the select and use add and
delete buttons for better use.
You can use Ctrl + Shift + J to find the first stage syntax errors
in any of the browser specially Firefox (as I am working in it).
You can debug your code line by line using Firebug for better
testing and error solving.
Please visit my website i.e. www.admecindia.co.in for more
blogs and write me at info@admecindia.co.in if you are
interested in learning JavaScript at advanced level.
Thanks
Learn Advanced AngularJS from Experts
ADMEC MULTIMEDIA INSTITUTE
Leader in Animation & Digital Media Education
ISO 9001 : 2008 CERTIFIED
- Visit Our Websites -
www.admecindia.co.in
www.graphic-design-institute.com
Phones: +91-9811-8181-22, +91-9911-7823-50
- Contact Us -
Interview Q&A of MVC in JavaScript
Theory:
Write down all the answers of given below questions and email me at the
given below email address.
● What is MVC?
● Why MVC is so important in JavaScript?
● Write down the roles and responsibilities of M, V, and C in a
JavaScript application.
● Explain all the useful and common tools and methods to debug
JavaScript.
Practical:
Create a record entry application that follow MVC code structure.
And don't forget to email me at: info@admecindia.co.in for the review.
Phones and Url:
Helpline 1: +91 9811-8181-22
Helpline 2: +91 9911-7823-50
Url: http://web-development-institute.com
Contact
ADMEC MULTIMEDIA INSTITUTE
Want to read more about our JavaScript Course, please visit
http://www.admecindia.co.in/javascript-master.html
Hey! Want to Learn Advanced JavaScript !!!
R

Contenu connexe

Tendances

Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript TutorialDHTMLExtreme
 
Java script basics
Java script basicsJava script basics
Java script basicsJohn Smith
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy stepsprince Loffar
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Jalpesh Vasa
 
Angular Mini-Challenges
Angular Mini-ChallengesAngular Mini-Challenges
Angular Mini-ChallengesJose Mendez
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java scriptDivyaKS12
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
Advisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptdominion
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentalsRajiv Gupta
 

Tendances (20)

Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Java script
Java scriptJava script
Java script
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Java script
Java scriptJava script
Java script
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Angular Mini-Challenges
Angular Mini-ChallengesAngular Mini-Challenges
Angular Mini-Challenges
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
Advisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScript
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
Java script
Java scriptJava script
Java script
 
J query
J queryJ query
J query
 

Similaire à MVC Design Pattern in JavaScript by ADMEC Multimedia Institute

AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran Wahle
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs WorkshopRan Wahle
 
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5  Building Your First Web Application (A Beginner S GuideASP.NET MVC 5  Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5 Building Your First Web Application (A Beginner S GuideAlicia Buske
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenSony Suci
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)M Ahsan Khan
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desaijinaldesailive
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamentalldcphuc
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnetrainynovember12
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!Roberto Messora
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCAnton Krasnoshchok
 
Top 10 Techniques For React Performance Optimization in 2022.pptx
Top 10 Techniques For React Performance Optimization in 2022.pptxTop 10 Techniques For React Performance Optimization in 2022.pptx
Top 10 Techniques For React Performance Optimization in 2022.pptxBOSC Tech Labs
 

Similaire à MVC Design Pattern in JavaScript by ADMEC Multimedia Institute (20)

AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
MVC & backbone.js
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5  Building Your First Web Application (A Beginner S GuideASP.NET MVC 5  Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamental
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnet
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
Top 10 Techniques For React Performance Optimization in 2022.pptx
Top 10 Techniques For React Performance Optimization in 2022.pptxTop 10 Techniques For React Performance Optimization in 2022.pptx
Top 10 Techniques For React Performance Optimization in 2022.pptx
 

Plus de Ravi Bhadauria

3 Important Terms of Post Production
3 Important Terms of Post Production3 Important Terms of Post Production
3 Important Terms of Post ProductionRavi Bhadauria
 
Basics of Video Editing | Types of Video Editing | Video Production Process
Basics of Video Editing | Types of Video Editing | Video Production ProcessBasics of Video Editing | Types of Video Editing | Video Production Process
Basics of Video Editing | Types of Video Editing | Video Production ProcessRavi Bhadauria
 
Basics of Media | Types of Media | Units in Media | Software in Media | Color...
Basics of Media | Types of Media | Units in Media | Software in Media | Color...Basics of Media | Types of Media | Units in Media | Software in Media | Color...
Basics of Media | Types of Media | Units in Media | Software in Media | Color...Ravi Bhadauria
 
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...Ravi Bhadauria
 
Elements and Principles of Design (Updated)
Elements and Principles of Design (Updated)Elements and Principles of Design (Updated)
Elements and Principles of Design (Updated)Ravi Bhadauria
 
Top Graphic Designing Hacks to Make You a Designing Pro Today
Top Graphic Designing Hacks to Make You a Designing Pro Today Top Graphic Designing Hacks to Make You a Designing Pro Today
Top Graphic Designing Hacks to Make You a Designing Pro Today Ravi Bhadauria
 
12 Famous Typographers to Inspire You
12 Famous Typographers to Inspire You12 Famous Typographers to Inspire You
12 Famous Typographers to Inspire YouRavi Bhadauria
 
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)Ravi Bhadauria
 
UX Design Essential Theories
UX Design Essential TheoriesUX Design Essential Theories
UX Design Essential TheoriesRavi Bhadauria
 
Workshop on resume, portfolio, interview
Workshop on resume, portfolio, interviewWorkshop on resume, portfolio, interview
Workshop on resume, portfolio, interviewRavi Bhadauria
 
Top 10 Architecture Design Colleges in India
Top 10 Architecture Design Colleges in IndiaTop 10 Architecture Design Colleges in India
Top 10 Architecture Design Colleges in IndiaRavi Bhadauria
 
User interface and user experience ui ux design basics
User interface  and user experience ui ux design basicsUser interface  and user experience ui ux design basics
User interface and user experience ui ux design basicsRavi Bhadauria
 
How to create Frost Neon Effect in Photoshop?
How to create Frost Neon Effect in Photoshop?How to create Frost Neon Effect in Photoshop?
How to create Frost Neon Effect in Photoshop?Ravi Bhadauria
 
Top 10 design colleges and institutes of india
Top 10 design colleges and institutes of indiaTop 10 design colleges and institutes of india
Top 10 design colleges and institutes of indiaRavi Bhadauria
 
Best Hollywood poster designers
Best Hollywood poster designersBest Hollywood poster designers
Best Hollywood poster designersRavi Bhadauria
 
Design Principles for All the Designers
Design Principles for All the DesignersDesign Principles for All the Designers
Design Principles for All the DesignersRavi Bhadauria
 
Content Writing Tips for SEO
Content Writing Tips for SEOContent Writing Tips for SEO
Content Writing Tips for SEORavi Bhadauria
 
6 Great Steps to Know to Create Successful Web GUI
6 Great Steps to Know to Create Successful Web GUI6 Great Steps to Know to Create Successful Web GUI
6 Great Steps to Know to Create Successful Web GUIRavi Bhadauria
 

Plus de Ravi Bhadauria (20)

3 Important Terms of Post Production
3 Important Terms of Post Production3 Important Terms of Post Production
3 Important Terms of Post Production
 
Basics of Video Editing | Types of Video Editing | Video Production Process
Basics of Video Editing | Types of Video Editing | Video Production ProcessBasics of Video Editing | Types of Video Editing | Video Production Process
Basics of Video Editing | Types of Video Editing | Video Production Process
 
Basics of Media | Types of Media | Units in Media | Software in Media | Color...
Basics of Media | Types of Media | Units in Media | Software in Media | Color...Basics of Media | Types of Media | Units in Media | Software in Media | Color...
Basics of Media | Types of Media | Units in Media | Software in Media | Color...
 
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
 
Elements and Principles of Design (Updated)
Elements and Principles of Design (Updated)Elements and Principles of Design (Updated)
Elements and Principles of Design (Updated)
 
Top Graphic Designing Hacks to Make You a Designing Pro Today
Top Graphic Designing Hacks to Make You a Designing Pro Today Top Graphic Designing Hacks to Make You a Designing Pro Today
Top Graphic Designing Hacks to Make You a Designing Pro Today
 
12 Famous Typographers to Inspire You
12 Famous Typographers to Inspire You12 Famous Typographers to Inspire You
12 Famous Typographers to Inspire You
 
Sargam UI Design
Sargam UI DesignSargam UI Design
Sargam UI Design
 
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
 
UX Design Essential Theories
UX Design Essential TheoriesUX Design Essential Theories
UX Design Essential Theories
 
Top 10 Ad Gurus
Top 10 Ad GurusTop 10 Ad Gurus
Top 10 Ad Gurus
 
Workshop on resume, portfolio, interview
Workshop on resume, portfolio, interviewWorkshop on resume, portfolio, interview
Workshop on resume, portfolio, interview
 
Top 10 Architecture Design Colleges in India
Top 10 Architecture Design Colleges in IndiaTop 10 Architecture Design Colleges in India
Top 10 Architecture Design Colleges in India
 
User interface and user experience ui ux design basics
User interface  and user experience ui ux design basicsUser interface  and user experience ui ux design basics
User interface and user experience ui ux design basics
 
How to create Frost Neon Effect in Photoshop?
How to create Frost Neon Effect in Photoshop?How to create Frost Neon Effect in Photoshop?
How to create Frost Neon Effect in Photoshop?
 
Top 10 design colleges and institutes of india
Top 10 design colleges and institutes of indiaTop 10 design colleges and institutes of india
Top 10 design colleges and institutes of india
 
Best Hollywood poster designers
Best Hollywood poster designersBest Hollywood poster designers
Best Hollywood poster designers
 
Design Principles for All the Designers
Design Principles for All the DesignersDesign Principles for All the Designers
Design Principles for All the Designers
 
Content Writing Tips for SEO
Content Writing Tips for SEOContent Writing Tips for SEO
Content Writing Tips for SEO
 
6 Great Steps to Know to Create Successful Web GUI
6 Great Steps to Know to Create Successful Web GUI6 Great Steps to Know to Create Successful Web GUI
6 Great Steps to Know to Create Successful Web GUI
 

Dernier

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Dernier (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

MVC Design Pattern in JavaScript by ADMEC Multimedia Institute

  • 1. R A Presentation by: Ravi Bhadauria ISO 9001 : 2008 CERTIFIED Learn JavaScript, jQuery, AngularJS from Expert in ADMEC MULTIMEDIA INSTITUTE www.admecindia.co.in | www.graphic-design-institute.com Phones: +91-9811-8181-22, +91-9911-7823-50 MVC Design Pattern in JavaScript
  • 2. MVC in JavaScript: A Practical Explanation ● MVC Introduction – What is MVC? – What is M in MVC? – What is V in MVC? – What is C in MVC? ● Use of MVC in an Application – Planning for an MVC Application – Writing code for Model – Writing code for View – Writing code for Controller ● Testing and Debugging – Useful tools – Validating the code By: Ravi Bhadauria Date: 22-01-2016 Purpose: Lecture
  • 3. Preface & Acknowledgment Dear reader, ADMEC Multimedia Institute is a growing institute that is providing industry oriented training in web design and web development along with multimedia, animation, graphic design, cad etc to the world at large. This presentation is one of the best presentations from our study material for our JavaScript Object Oriented workshops which ADMEC conducts every week at the center. We have planned to share it with the world so that everyone can take benefits from our small efforts. This presentation contains a brief information for “MVC Design Patterns in JavaScript”. We express thanks to many books and websites for making it one of the best presentations of all the time. Thanks Ravi Bhadauria, Instructor (Web UI and Back-end Development) Profile: Director ADMEC Multimedia Institute Url: http://www.admecindia.co.in
  • 4. What is MVC? Earlier I was working in ActionScript and PHP. I used to think that it is only my favorite programming but when I started using JavaScript in 2006 then it changed my opinion. Now JavaScript is my one of the best programming languages that I am using for client side and server side requirements. The reason behind that is its simplicity and scalability. Other programmings start buckling up as they get bigger or larger while JavaScript provides an easy to use and easy to understand manner in that situation. MVC is a design pattern that provide design solution for JavaScript programmers. MVC is not a JavaScript specific design patter; it is being used by many languages as it is a best practice to code which is scalable, flexible, modular, and easy to manage.
  • 5. What is M letter in MVC? M is one of the most important components of MVC. M stands for Model. Model is the domain-specific representation of the information on which the application operates. Model handles the business logic and database related responsibilities. Domain logic adds meaning to raw data (e.g. calculating if today is the user’s birthday, or the totals, taxes and shipping charges for shopping cart items).
  • 6. What is V letter in MVC? V stands for View in MVC. It handles the presentation of the web page or web application. It fetches the data from model and renders that into a form suitable for interaction, typically a user interface element. MVC is often seen in web applications, where the view is the HTML page and the code which gathers dynamic data for the page.
  • 7. What is C letter in MVC? C is the last and very important component of MVC as it controls the application logic and It is known as Controller. It helps in processing and responding to events, typically user actions, and invokes changes on the model and perhaps the view.
  • 8. How MVC Improves JavaScript? What is a robust and successful application of JavaScript? The answer is very simple: “An application which has good features, provides best performance, and scale well when needed” And I would say that MVC is the only rescue of such applications in JavaScript to provide such features.
  • 9. Creating an Application using MVC I will show you how you can create a list of items which can be manipulated using two buttons. The data of the component is just a list of items, in which one particular item can be selected and deleted. So, the model of the component is very simple - it consists of an array and a selected item index; and here it is on the next slide.
  • 10. Learn Advanced JavaScript from Experts ADMEC MULTIMEDIA INSTITUTE Leader in Animation & Digital Media Education ISO 9001 : 2008 CERTIFIED - Visit Our Websites - www.admecindia.co.in Phones: +91-9811-8181-22, +91-9911-7823-50 - Contact Us -
  • 11. Planning for the UI in JavaScript UI would be very simple with just 3 elements. You should use Bootstrap's CSS and jQuery library for better results.
  • 12. Implementing Observer Pattern - I Event is a simple class for implementing the Observer pattern: function Event(sender) { this._sender = sender; this._listeners = []; } Event.prototype = { attach : function (listener) { this._listeners.push(listener); },
  • 13. Implementing Observer Pattern - II notify : function (args) { var index; for (index = 0; index < this._listeners.length; index += 1) { this._listeners[index](this._sender, args); } } };
  • 14. Coding Model First - I /** * The Model. Model stores items and notifies * observers about changes. */ function ListModel(items) { this._items = items; this._selectedIndex = -1; this.itemAdded = new Event(this); this.itemRemoved = new Event(this); this.selectedIndexChanged = new Event(this); }
  • 15. Coding Model First - II ListModel.prototype = { getItems : function () { return [].concat(this._items); }, addItem : function (item) { this._items.push(item); this.itemAdded.notify({ item : item }); },
  • 16. Coding Model First - III removeItemAt : function (index) { var item; item = this._items[index]; this._items.splice(index, 1); this.itemRemoved.notify({ item : item }); if (index === this._selectedIndex) { this.setSelectedIndex(-1); } },
  • 17. Coding Model First - IV getSelectedIndex : function () { return this._selectedIndex; }, setSelectedIndex : function (index) { var previousIndex; previousIndex = this._selectedIndex; this._selectedIndex = index; this.selectedIndexChanged.notify({ previous : previousIndex }); } };
  • 18. Coding View then - I /** * The View. View presents the model and provides * the UI events. The controller is attached to these * events to handle the user interraction. */ function ListView(model, elements) { this._model = model; this._elements = elements; this.listModified = new Event(this); this.addButtonClicked = new Event(this); this.delButtonClicked = new Event(this);
  • 19. Coding View then - II var _this = this; // attach model listeners this._model.itemAdded.attach(function () { _this.rebuildList(); }); this._model.itemRemoved.attach(function () { _this.rebuildList(); });
  • 20. Coding View then - III // attach listeners to HTML controls this._elements.list.change(function (e) { _this.listModified.notify({ index : e.target.selectedIndex }); }); this._elements.addButton.click(function () { _this.addButtonClicked.notify(); }); this._elements.delButton.click(function () { _this.delButtonClicked.notify(); }); }
  • 21. Coding View then - IV ListView.prototype = { show : function () { this.rebuildList(); }, rebuildList : function () { var list, items, key; list = this._elements.list; list.html('');
  • 22. Coding View then - V items = this._model.getItems(); for (key in items) { if (items.hasOwnProperty(key)) { list.append($('<option>' + items[key] + '</option>')); } } this._model.setSelectedIndex(-1); } };
  • 23. Coding Controller Finally - I /** * The Controller. Controller responds to user actions and * invokes changes on the model. */ function ListController(model, view) { this._model = model; this._view = view; var _this = this;
  • 24. Coding Controller Finally - II this._view.listModified.attach(function (sender, args) { _this.updateSelected(args.index); }); this._view.addButtonClicked.attach(function () { _this.addItem(); }); this._view.delButtonClicked.attach(function () { _this.delItem(); }); }
  • 25. Coding Controller Finally - III ListController.prototype = { addItem : function () { var item = window.prompt('Add item:', ''); if (item) { this._model.addItem(item); } }, delItem : function () { var index;
  • 26. Coding Controller Finally - IV index = this._model.getSelectedIndex(); if (index !== -1) { this._model.removeItemAt(this._model.getSelectedIndex()); } }, updateSelected : function (index) { this._model.setSelectedIndex(index); } };
  • 27. The HTML <div class="row container"> <div class="col-xs-4"> <select id="list" class="form-control" size="10"></select> </div> <div class="col-xs-8"> <button id="plusBtn" class="btn btn-default btn-block">+</button> <button id="minusBtn" class="btn btn-default btn-block">-</button> </div> </div> And I hope you didn't forget add Bootstrap CSS, jQuery Library, and MVC JavaScript file which we created recently.
  • 28. Clubbing up all And of course, the Model, View, and Controller classes should be instantiated. The sample, which you can below, uses the following code to instantiate and configure the classes. You should put this code inside the html page just before closing body. $(function () { var model = new ListModel(['PHP', 'ActionScript', 'JavaScript']), view = new ListView(model, { 'list' : $('#list'), 'addButton' : $('#plusBtn'), 'delButton' : $('#minusBtn') }), controller = new ListController(model, view); view.show(); });​
  • 29. Testing MVC Application in JavaScript Open your html page in any of the browser and test. I am sure you will have some lists inside the select and use add and delete buttons for better use. You can use Ctrl + Shift + J to find the first stage syntax errors in any of the browser specially Firefox (as I am working in it). You can debug your code line by line using Firebug for better testing and error solving. Please visit my website i.e. www.admecindia.co.in for more blogs and write me at info@admecindia.co.in if you are interested in learning JavaScript at advanced level. Thanks
  • 30. Learn Advanced AngularJS from Experts ADMEC MULTIMEDIA INSTITUTE Leader in Animation & Digital Media Education ISO 9001 : 2008 CERTIFIED - Visit Our Websites - www.admecindia.co.in www.graphic-design-institute.com Phones: +91-9811-8181-22, +91-9911-7823-50 - Contact Us -
  • 31. Interview Q&A of MVC in JavaScript Theory: Write down all the answers of given below questions and email me at the given below email address. ● What is MVC? ● Why MVC is so important in JavaScript? ● Write down the roles and responsibilities of M, V, and C in a JavaScript application. ● Explain all the useful and common tools and methods to debug JavaScript. Practical: Create a record entry application that follow MVC code structure. And don't forget to email me at: info@admecindia.co.in for the review.
  • 32. Phones and Url: Helpline 1: +91 9811-8181-22 Helpline 2: +91 9911-7823-50 Url: http://web-development-institute.com Contact ADMEC MULTIMEDIA INSTITUTE Want to read more about our JavaScript Course, please visit http://www.admecindia.co.in/javascript-master.html Hey! Want to Learn Advanced JavaScript !!! R