CSC/ECE 517 Fall 2013/ch1 1w26 as: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Introduction to MVC=
=Introduction to MVC=


MVC architecture is a design pattern which separates the representation of data from users interaction with it.<ref>http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller</ref>  
MVC architecture is a design pattern which separates the representation of data from users interacting with it.<ref>http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller</ref>  


It consists of 3 major components:
It consists of 3 major components:


*The model: In MVC, M stands for Model. A Model is a collection of Objects which encapsulates the data in the database and provides an interface to access it.  
*The model: In MVC, M stands for Model. A Model is a collection of [http://en.wikipedia.org/wiki/Object_(computer_science) Objects] which encapsulates the data in the database and provides an interface to access it.  


*The view: A View is called the presentation layer, and this is where the data from the model is represented generally on a web browser.
*The view: A View is called the presentation layer, and this is where the data from the model is represented generally on a web browser.
Line 12: Line 12:
This kind of architecture is very popular among web applications.
This kind of architecture is very popular among web applications.


MVC architecture simplifies and modularizes the approach to creating a web application. Now let us discuss how MVC design pattern is supported in Rails, and how does it differ when compared with other popular languages.
MVC architecture simplifies and modularizes the approach to creating a web application. Now let us discuss how MVC design pattern is supported in [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails], and how does it differ when compared with other popular languages.


[[File:MVC.jpg|frame|Fig 1:Figure showing how Model, View and Controller works in the background]]


=MVC in Rails=
=MVC in Rails<ref>http://www.cs.toronto.edu/~wl/csc309/handouts/rails.pdf</ref>=
To understand how the MVC architecture works in the background, let us take an example of web browsing.  
To understand how the MVC architecture works in the background, let us take an example of web browsing.  
The following is the sequence in which the process goes about:
The following is the sequence in which the process goes about:
Line 26: Line 27:


==Example from a Rails application:==
==Example from a Rails application:==
# Incoming requests are sent to a ‘Router’ which determines where to parse the request and forward it.
# Incoming requests are sent to a [http://en.wikipedia.org/wiki/Router_(computing) ‘Router’] which determines where to parse the request and forward it.
# The request if forwarded to a controller, wherein a particular method/action is called.
# The request if forwarded to a controller, wherein a particular method/action is called.
# Using the data available in the request, the action interacts with the model or it causes other action to be invoked.
# Using the data available in the request, the action interacts with the model or it causes other action to be invoked.
# The action then prepares the information for the ‘View’ which renders the output to the user.
# The action then prepares the information for the ‘View’ which renders the output to the user.
[[File:Rails and MVC.jpg|frame]]
   
   
Rails handles all the low-level details which would otherwise take so long to do it by self, so that you can concentrate on the application’s core functionality.
Rails handles all the low-level details which would otherwise take so long to do it by self, so that you can concentrate on the application’s core functionality.
Line 35: Line 38:
==Rails principles==
==Rails principles==
# Convention over configuration: By using standard conventions, we can avoid the need for explicit mapping such as deployment descriptors. The naming conventions would automatically perform mapping (like between controller and view)
# Convention over configuration: By using standard conventions, we can avoid the need for explicit mapping such as deployment descriptors. The naming conventions would automatically perform mapping (like between controller and view)
# Don’t Repeat Yourself (DRY): While using Rails, we make sure that the required information we might user time and again to execute the same functionality is stored in a single unambiguous place.
# Don’t Repeat Yourself (DRY): While using Rails, we make sure that the required information we might user time and again to execute the same functionality is stored in a single unambiguous place.


==Inside Rails==
==Inside Rails==
# Active Record (Model) -
# [http://guides.rubyonrails.org/active_record_querying.html Active Record] (Model) - This is the model support in Rails. In the ORM<ref>http://en.wikipedia.org/wiki/Object-relational_mapping</ref> layer supplied with Rails - tables map to classes, rows to objects, and columns to object attributes.
# Action Pack (View and Controller) – This bundles both the view and controller components which are quite intimate. The controller supplies data to the view and also receives events from the pages generated by the views.
# Action Pack (View and Controller) – This bundles both the view and controller components which are quite intimate. The controller supplies data to the view and also receives events from the pages generated by the views.


Line 51: Line 53:


==Ruby==
==Ruby==
In the recent times Ruby on Rails has become a popular choice for creating applications on the web. Its popularity is mainly attributed to its ease of use, and also the short time it takes in creating and deploying an application.
In the recent times Ruby on Rails has become a popular<ref>http://en.wikipedia.org/wiki/Programming_languages_used_in_most_popular_websites</ref> choice for creating applications on the web. Its popularity is mainly attributed to its ease of use, and also the short time it takes in creating and deploying an application.


Following are the list of famous websites that have been built using the Ruby on Rails framework
Following are the list of famous websites<ref>http://www.developerdrive.com/2011/09/20-best-sites-built-with-ruby-on-rails/</ref> that have been built using the Ruby on Rails framework


*Scribd
*[http://www.scribd.com/  Scribd]
*Hulu
*[http://www.hulu.com/  Hulu]
*CrunchBase
*[http://www.crunchbase.com/  CrunchBase]
*Slideshare
*[http://www.slideshare.net/  Slideshare]
*Github
*[https://github.com/  Github]
*Yellow Pages
*[http://www.yellowpages.com/  Yellow Pages]
   
   
==Java==
==Java==
In the Java world, the MVC architecture for web applications is achieved by using the Spring MVC framework, along with an ORM tool like Hibernate.  
In the Java world, the MVC architecture for web applications is achieved by using the [http://en.wikipedia.org/wiki/Spring_Framework Spring MVC]<ref>http://zeroturnaround.com/rebellabs/the-curious-coders-guide-to-java-web-frameworks-spring-mvc/#!/</ref><ref>http://www.quora.com/Java-programming-language/What-are-some-famous-websites-written-in-Java</ref> framework, along with an ORM tool like Hibernate.  


Following are the list of popular websites which have been implemented using the Spring MVC framework
Following are the list of popular websites<ref>http://thewhitecover.com/10-best-high-traffic-sites-built-in-java-servlet-including-gmail-and-amazon/</ref> which have been implemented using the Java Spring MVC framework


*[[http://www.gmail.com|Gmail]]
*[http://www.gmail.comGmail]
*LinkedIn
*[http://www.linkedin.com/  LinkedIn]
*Amazon
*[http://www.amazon.com/  Amazon]
*eBay
*[http://www.ebay.com/  eBay]
*Google Talk
*[http://www.google.com/hangouts/  Google Talk]
*Tagged
*[http://www.tagged.com/  Tagged]


==JavaScript==
==JavaScript==
In the JavaScript world, MVC architecture is often achieved by using a 3rd party library. Some of the popular javascript libraries in use to create MVC applications using JavaScript are Backbone.js, Ember.js, Cappuccino, Spine.js, JavaScript MVC and Google Closure.
In the JavaScript world, MVC architecture is often achieved by using a 3rd party library. Some of the popular javascript libraries<ref>http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/</ref> in use to create MVC applications using JavaScript are [http://backbonejs.org/ Backbone.js], [http://emberjs.com/ Ember.js], [http://www.cappuccino-project.org/ Cappuccino], [http://spinejs.com/ Spine.js], [http://javascriptmvc.com/ JavaScript MVC] and [http://en.wikipedia.org/wiki/Google_Closure_Tools Google Closure].


==PHP==
==PHP==
As with JavaScript even PHP has a ton of 3rd party frameworks offering the much need MVC architecture support. Prade, Seagull, CakePHP, WASP are some of the popular ones.
As with JavaScript even PHP has a ton of 3rd party frameworks<ref>http://jonathanmh.com/best-php-mvc-frameworks-of-2013/</ref> offering the much need MVC architecture support. Prade, Seagull, CakePHP, WASP are some of the popular ones.


Following are the list of popular websites which have been implemented using the MVC framework through PHP:
Following are the list of popular websites<ref>http://susprod.com/famous-sites-that-use-php/#.UjnaLsZ6Zec</ref><ref>http://stackoverflow.com/questions/1906795/what-are-some-famous-websites-built-in-django</ref> which have been implemented using the MVC framework through PHP:
*Facebook
*[https://www.facebook.com/  Facebook]
*Apple
*[http://www.apple.com/  Apple]
*Wikipedia
*[http://www.wikipedia.org/  Wikipedia]
*Yahoo
*[http://www.yahoo.com/  Yahoo]
*Flickr
*[http://www.flickr.com/  Flickr]
*Vimeo
*[https://vimeo.com/  Vimeo]


PHP is the most commonly used web framework on the internet. This trend has observed some variation in the last decade due to the gain in popularity of Object-Oriented languages such as Java, Ruby, Python, etc.
PHP is the most commonly used web framework on the internet. This trend has observed some variation in the last decade due to the gain in popularity of Object-Oriented languages such as Java, Ruby, Python, etc.


==Python==
==Python==
Django is the goto framework for implementing web applications following the MVC architecture in Python.
[http://en.wikipedia.org/wiki/Django_(web_framework) Django] is the goto framework for implementing web applications following the MVC architecture in Python.


Following are the list of popular websites which have been implemented using Django and Python:
Following are the list of popular websites<ref>http://lineofthought.com/tools/python</ref> which have been implemented using Django and Python:
*Pinterest
*[https://www.pinterest.com/  Pinterest]
*Instagram
*[http://instagram.com/  Instagram]
*Yelp
*[http://www.yelp.com/  Yelp]
*Reddit
*[http://www.reddit.com/  Reddit]
*Chess
*[http://www.chess.com/  Chess]
*Dropbox
*[https://www.dropbox.com/  Dropbox]


=Differences between the MVC architecture as compared to Ruby on Rails’s and other popular frameworks=
=Differences between the MVC architecture as compared to Ruby on Rails’s and other popular frameworks=
 
Most MVC frameworks have a lot of features in common<ref>http://stackoverflow.com/questions/9179848/do-mvc-frameworks-vary-greatly-from-one-language-to-another-ie-asp-net-python</ref>, and talking about which framework is the most suited one to build a web application is a highly subjective topic. In most cases the answer to this question is derived by thoroughly analyzing the case at hand. For instance enterprises whose applications are already running on the JVM platform would often go ahead with the Spring MVC framework coupled with an ORM tool like hibernate. New startups which are set up in a fast paced development environment often prefer to work with Ruby on Rails as it follows the dry (don’t repeat yourself) approach. Now let us see where exactly the differences lie amongst these frameworks
Most MVC frameworks have a lot of features in common, and talking about which framework is the most suited one to build a web application is a highly subjective topic. In most cases the answer to this question is derived by thoroughly analyzing the case at hand. For instance enterprises whose applications are already running on the JVM platform would often go ahead with the Spring MVC framework coupled with an ORM tool like hibernate. New startups which are set up in a fast paced development environment often prefer to work with Ruby on Rails as it follows the dry (don’t repeat yourself) approach. Now let us see where exactly the differences lie amongst these frameworks


==Convention over Configuration==
==Convention over Configuration==
Line 115: Line 116:


==Full MVC vs Simple MVC==
==Full MVC vs Simple MVC==
MVC frameworks can typically be classified into two types. Full MVC and Simple MVC. Full MVC frameworks go beyond the concept of model-view-controller, and offer additional features to build more complex web application. If you consider Rails, Spring MVC or the Django framework. All these frameworks offer a standard ORM (Object Relational Mapping for data access). Spring in addition also offers an IOC (Injection of Control) container while Django offers an interface  for the model. If you consider these frameworks to be Full MVC’s then ASP .Net’s framework leaves out the modules like IOC and ORM, and hence can be referred to as a Simple MVC.
MVC frameworks can typically be classified into two types. Full MVC and Simple MVC. Full MVC frameworks go beyond the concept of model-view-controller, and offer additional features to build more complex web application. If you consider Rails, Spring MVC or the Django framework. All these frameworks offer a standard [http://en.wikipedia.org/wiki/Object-relational_mapping ORM] (Object Relational Mapping for data access). Spring in addition also offers an [http://www.subshell.com/en/subshell/blog/Spring-3-MVC-Dependency-Injection-for-annotated-Controllers100.html#jumpto IOC] (Injection of Control) container while Django offers an interface  for the model. If you consider these frameworks to be Full MVC’s then ASP .Net’s framework leaves out the modules like IOC and ORM, and hence can be referred to as a Simple MVC.


==Language dependence==
==Language dependence==
Most MVC frameworks induce the restraint of using a specific programming language. For instance Rails requires one to program in Ruby, whereas using Django required the developer to program in Python. However using Spring gives the option of potentially using any programming language that can run on the JVM (java virtual machine).  
Most MVC frameworks induce the restraint of using a specific programming language. For instance Rails requires one to program in Ruby, whereas using Django required the developer to program in Python. However using Spring gives the option of potentially using any programming language that can run on the [http://en.wikipedia.org/wiki/Java_virtual_machine JVM] (java virtual machine).  


==Conclusion==
=Conclusion=
So based on the above differences if we have to make some conclusions then we what we have at hand is that while using a framework like Rails we can get up and keep running quickly, but could run into problem if and when we try to venture outside the framework designed boundaries. Spring offers a complete enterprise platform which in a few cases might be a overwhelming set of features as many of them are largely unused. Choosing a simple ASP .Net framework would set us up with a nice web layer, but apart from that rest of the application plumbing work would be a responsibility of the developer.
So based on the above differences if we have to make some conclusions then we what we have at hand is that while using a framework like Rails we can get up and keep running quickly, but could run into problem if and when we try to venture outside the framework designed boundaries. Spring offers a complete enterprise platform which in a few cases might be a overwhelming set of features as many of them are largely unused. Choosing a simple ASP .Net framework would set us up with a nice web layer, but apart from that rest of the application plumbing work would be a responsibility of the developer.


=References=
=References=
<references/>
<references/>
#http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
#http://www.cs.toronto.edu/~wl/csc309/handouts/rails.pdf
#http://stackoverflow.com/questions/9179848/do-mvc-frameworks-vary-greatly-from-one-language-to-another-ie-asp-net-python
#http://en.wikipedia.org/wiki/Object-relational_mapping
#http://zeroturnaround.com/rebellabs/the-curious-coders-guide-to-java-web-frameworks-spring-mvc/#!/
#http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/
#http://jonathanmh.com/best-php-mvc-frameworks-of-2013/
#http://thewhitecover.com/10-best-high-traffic-sites-built-in-java-servlet-including-gmail-and-amazon/
#http://www.quora.com/Java-programming-language/What-are-some-famous-websites-written-in-Java
#http://susprod.com/famous-sites-that-use-php/#.UjnaLsZ6Zec
#http://en.wikipedia.org/wiki/Programming_languages_used_in_most_popular_websites
#http://www.developerdrive.com/2011/09/20-best-sites-built-with-ruby-on-rails/
#http://stackoverflow.com/questions/1906795/what-are-some-famous-websites-built-in-django
#http://lineofthought.com/tools/python

Latest revision as of 16:44, 24 September 2013

Introduction to MVC

MVC architecture is a design pattern which separates the representation of data from users interacting with it.<ref>http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller</ref>

It consists of 3 major components:

  • The model: In MVC, M stands for Model. A Model is a collection of Objects which encapsulates the data in the database and provides an interface to access it.
  • The view: A View is called the presentation layer, and this is where the data from the model is represented generally on a web browser.
  • The controller: A Controller handles the decision making process and communicates with the Model to access the data.

This kind of architecture is very popular among web applications.

MVC architecture simplifies and modularizes the approach to creating a web application. Now let us discuss how MVC design pattern is supported in Rails, and how does it differ when compared with other popular languages.

Fig 1:Figure showing how Model, View and Controller works in the background

MVC in Rails<ref>http://www.cs.toronto.edu/~wl/csc309/handouts/rails.pdf</ref>

To understand how the MVC architecture works in the background, let us take an example of web browsing. The following is the sequence in which the process goes about:

  1. The user enters the URL of the page he wishes to visit.
  2. The controller interacts with the model to fetch the particular request and invokes the view to render the new view.
  3. The view renders the required web page and displays it to the user/client.

In Rails, the model, view and controller and separate entities functionally which are knitted together to perform the required functions.


Example from a Rails application:

  1. Incoming requests are sent to a ‘Router’ which determines where to parse the request and forward it.
  2. The request if forwarded to a controller, wherein a particular method/action is called.
  3. Using the data available in the request, the action interacts with the model or it causes other action to be invoked.
  4. The action then prepares the information for the ‘View’ which renders the output to the user.

Rails handles all the low-level details which would otherwise take so long to do it by self, so that you can concentrate on the application’s core functionality.

Rails principles

  1. Convention over configuration: By using standard conventions, we can avoid the need for explicit mapping such as deployment descriptors. The naming conventions would automatically perform mapping (like between controller and view)
  2. Don’t Repeat Yourself (DRY): While using Rails, we make sure that the required information we might user time and again to execute the same functionality is stored in a single unambiguous place.

Inside Rails

  1. Active Record (Model) - This is the model support in Rails. In the ORM<ref>http://en.wikipedia.org/wiki/Object-relational_mapping</ref> layer supplied with Rails - tables map to classes, rows to objects, and columns to object attributes.
  2. Action Pack (View and Controller) – This bundles both the view and controller components which are quite intimate. The controller supplies data to the view and also receives events from the pages generated by the views.

View:

Action Pack provides View support by helping create either all or part of a page to be displayed in the browser. The dynamic content is generated by templates.

Controller:

Coordinates the action between the user, the views and the model. Rails handles most of this functionality behind the scene and lets you concentrate on the application-level functionality. The controller also routes external requests to internal actions, manages caching, manages helper modules and sessions.

MVC applications in popular programming languages

Ruby

In the recent times Ruby on Rails has become a popular<ref>http://en.wikipedia.org/wiki/Programming_languages_used_in_most_popular_websites</ref> choice for creating applications on the web. Its popularity is mainly attributed to its ease of use, and also the short time it takes in creating and deploying an application.

Following are the list of famous websites<ref>http://www.developerdrive.com/2011/09/20-best-sites-built-with-ruby-on-rails/</ref> that have been built using the Ruby on Rails framework

Java

In the Java world, the MVC architecture for web applications is achieved by using the Spring MVC<ref>http://zeroturnaround.com/rebellabs/the-curious-coders-guide-to-java-web-frameworks-spring-mvc/#!/</ref><ref>http://www.quora.com/Java-programming-language/What-are-some-famous-websites-written-in-Java</ref> framework, along with an ORM tool like Hibernate.

Following are the list of popular websites<ref>http://thewhitecover.com/10-best-high-traffic-sites-built-in-java-servlet-including-gmail-and-amazon/</ref> which have been implemented using the Java Spring MVC framework

JavaScript

In the JavaScript world, MVC architecture is often achieved by using a 3rd party library. Some of the popular javascript libraries<ref>http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/</ref> in use to create MVC applications using JavaScript are Backbone.js, Ember.js, Cappuccino, Spine.js, JavaScript MVC and Google Closure.

PHP

As with JavaScript even PHP has a ton of 3rd party frameworks<ref>http://jonathanmh.com/best-php-mvc-frameworks-of-2013/</ref> offering the much need MVC architecture support. Prade, Seagull, CakePHP, WASP are some of the popular ones.

Following are the list of popular websites<ref>http://susprod.com/famous-sites-that-use-php/#.UjnaLsZ6Zec</ref><ref>http://stackoverflow.com/questions/1906795/what-are-some-famous-websites-built-in-django</ref> which have been implemented using the MVC framework through PHP:

PHP is the most commonly used web framework on the internet. This trend has observed some variation in the last decade due to the gain in popularity of Object-Oriented languages such as Java, Ruby, Python, etc.

Python

Django is the goto framework for implementing web applications following the MVC architecture in Python.

Following are the list of popular websites<ref>http://lineofthought.com/tools/python</ref> which have been implemented using Django and Python:

Differences between the MVC architecture as compared to Ruby on Rails’s and other popular frameworks

Most MVC frameworks have a lot of features in common<ref>http://stackoverflow.com/questions/9179848/do-mvc-frameworks-vary-greatly-from-one-language-to-another-ie-asp-net-python</ref>, and talking about which framework is the most suited one to build a web application is a highly subjective topic. In most cases the answer to this question is derived by thoroughly analyzing the case at hand. For instance enterprises whose applications are already running on the JVM platform would often go ahead with the Spring MVC framework coupled with an ORM tool like hibernate. New startups which are set up in a fast paced development environment often prefer to work with Ruby on Rails as it follows the dry (don’t repeat yourself) approach. Now let us see where exactly the differences lie amongst these frameworks

Convention over Configuration

Ruby on Rails follows the rule ‘Convention over Configuration’. So this typically means that there is not a lot of configuration that has to be done. The framework has a number of naming conventions pre-defined and using these in our application as per the rules would get our application up and running in no time. In a framework like Spring MVC we generally have to do with a lot of XML configuration, and we would have to write a lot more code than we do when using the Rails framework.

Presentation Layer(View)

With the Ruby framework the Views are generally a mix of HTML and your regular ruby code. But take the case of the Django MVC framework used with Python. In Django we use a template language to define the View component.

Level of Modularity

Many MVC frameworks offers many type of View engines to work with. For example Spring MVC. Whereas other frameworks like Ruby offers only one way to do it. This actually decreases the level of modularity for an application.

Full MVC vs Simple MVC

MVC frameworks can typically be classified into two types. Full MVC and Simple MVC. Full MVC frameworks go beyond the concept of model-view-controller, and offer additional features to build more complex web application. If you consider Rails, Spring MVC or the Django framework. All these frameworks offer a standard ORM (Object Relational Mapping for data access). Spring in addition also offers an IOC (Injection of Control) container while Django offers an interface for the model. If you consider these frameworks to be Full MVC’s then ASP .Net’s framework leaves out the modules like IOC and ORM, and hence can be referred to as a Simple MVC.

Language dependence

Most MVC frameworks induce the restraint of using a specific programming language. For instance Rails requires one to program in Ruby, whereas using Django required the developer to program in Python. However using Spring gives the option of potentially using any programming language that can run on the JVM (java virtual machine).

Conclusion

So based on the above differences if we have to make some conclusions then we what we have at hand is that while using a framework like Rails we can get up and keep running quickly, but could run into problem if and when we try to venture outside the framework designed boundaries. Spring offers a complete enterprise platform which in a few cases might be a overwhelming set of features as many of them are largely unused. Choosing a simple ASP .Net framework would set us up with a nice web layer, but apart from that rest of the application plumbing work would be a responsibility of the developer.

References

<references/>