CSC/ECE 517 Fall 2009/wiki1b 13 a1: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(59 intermediate revisions by the same user not shown)
Line 3: Line 3:
== Introduction ==
== Introduction ==


The Model View Controller design pattern (MVC) proposes the separation of duties in a software application among three components, each with a distinct and specialized responsibility. The components are a model, a view, and a controller. The model handles the data which is used by the application and the necessary business logic, and is not concerned with the presentation layer or the navigation logic. The view specializes in the presentation of the data or part of it in a way that is accessible to the user, usually a Graphical User Interface (GUI). The controller is in charge of  processing the interaction between the user and the application, usually the navigation logic [10, 15].
The '''Model View Controller''' (MVC) is an architectural design pattern for object-oriented software applications. MVC proposes the use of three different types of components to handle core application functionality. Each component has a distinct and specialized responsibility. The components of an MVC application are: a model, a view, and a controller.  


* The '''model''' handles the data which is used by the application. The functionality provided by the model includes retrieving data from its source, usually a relational database, and saving such data once it has changed. The model also enforces the  business logic needed to preserve the validity of the data.
* The '''view''' handles the presentation of the data or portions of it in a way that is accessible to the user, usually a Graphical User Interface (GUI). The view is solely concerned with the display of the data and does not perform any validation or business logic.
* The '''controller''' is in charge of processing the interaction between the user and the application. The controller determines which model methods should be invoked in response to user actions. Once data is delivered by the model, the controller also determines which view should display it. In the case of web applications, the controller is where navigation logic is processed [10, 15].
The following diagram illustrates a typical scenario for a web application implemented using the MVC pattern.
[[Image:MVC_Diagram.JPG]]
'''
'''


== History ==
== History ==


The MVC pattern was first proposed by "Trygve Reenskaugh in 1979 and implemented by Jim Althoff for Smalltalk-80 [8]." The first implementation of MVC took place at the Xerox PARC research lab as part of the Smalltalk-80 user interface [7]. Smalltalk-80 was a highly interactive graphical user interface which became the precursor of the Apple Lisa and later the Macintosh. The principles of MVC have largely influenced the software developed for the Mac.


The MVC pattern was first proposed by "Trygve Reenskaugh in 1979 and implemented by Jim Althoff for Smalltalk-80[8]." The first implementation of MVC took place at the Xerox PARC research lab as part of the Smalltalk-80 user interface [7]. Smalltalk-80 was a highly interactive graphical user interface which became the precursor of the Apple Lisa and later the Macintosh.
The MVC was originally conceived for the implementation of interactive desktop applications with a graphical user interface. Other than the work on Smalltalk and Apple, MVC did not enjoy much popularity in subsequent years. The advent of the web changed things. Initial web applications were written with little or no separation of concerns. A typical web application would combine presentation, business, and data retrieval logic on a single file of code. As applications became more complex, maintenance issues became apparent. Developers started looking for ways to better structure web applications, which resulted in the emergence of the MVC pattern as a very popular choice to provide a solution.  


One of the first widely used applications of the MVC pattern on web applications appeared as part of the Java Server Pages (JSP) specification, known as Model 2 [2, 10].  Model 2 implements MVC in Java using Servlets and Java beans to implement web applications. Another very popular Java implementation of the MVC patter is the open source project [http://struts.apache.org/ Apache Struts]. Struts provides the necessary framework to write web applications in Java following the MCV design pattern[1]. The Struts framework has been in wide use since 2001[18].
One of the first widely used applications of the MVC pattern on web applications appeared as part of the Java Server Pages (JSP) specification, known as Model 2 [2, 10].  Model 2 implements MVC in Java using Servlets, [http://java.sun.com/javase/technologies/desktop/javabeans/index.jsp Java Beans], and JSPs. Model 2 is perhaps the most popular implementation of the MVC pattern currently in use.  


Following the Java implementation came Microsoft's MVC versions for the Active Server Pages platform [16]. Initially MVC was proposed as part of the Microsoft Enterprise Library and recently it has become a full-fledged product, integral part of the latest version of ASP.NET and Visual Studio .NET, http://www.asp.net/mvc/.
Another very popular Java implementation of the MVC pattern is the open source project [http://struts.apache.org/ Apache Struts]. Struts provides the necessary framework to write web applications in Java following the MCV design pattern [1] using Java Server Pages (JSP) and Java Servlets as the main building blocks. The Struts framework has been in wide use since 2001 when the [http://jakarta.apache.org/ Jakarta] project gained popularity [18].


Currently one of the most popular implementations of MVC can be found as part of the Rails framework for web-based development using Ruby. MVC is at the heart of Ruby on Rails and its principles determine how web applications should be structured [14].
Following the Java implementations came Microsoft's MVC versions for the Active Server Pages platform [16]. Initially MVC was proposed as part of the Microsoft Enterprise Library. The enterprise library is a set of suggested best practices along with standard code targeted to .NET Framework developers. Recently Microsoft has turned its MVC implementation into a full-fledged product, integral part of the latest version of ASP.NET and Visual Studio .NET [3].
 
Currently one of the most popular implementations of MVC can be found as part of the Rails framework for web-based development using Ruby. MVC is at the heart of [http://rubyonrails.org/ Ruby on Rails] and its principles determine how web applications written in the framework are structured [14]. Ruby on Rails is one of the factors that has largely contributed to the popularity of the Ruby language.
'''


== Benefits and Applications ==
== Benefits and Applications ==




The main strength of the MVC pattern is that it separates the data, application, and representation logic form each other. In essence, applications are built using a separation of duties such that elements needed for an application to function are self-contained in distinct components that specializes in one of these core functions. Additional benefits of the MVC pattern include:
* The main benefit of the MVC pattern is that it separates the data, application, and presentation logic from each other. Applications built following the MVC pattern result in an implementation that is more cohesive and less coupled. The essential functionality needed for an application's functionality is located in distinct components that specialize in one of the three core functions.  


* Increase code reuse
* The MVC pattern is an ideal choice for structuring web applications, where high interactivity is expected. MVC is particularly useful in applications where the same data must be presented in different ways. An example of this is a web-based catalog that offers a different interface for a desktop web browser and a more streamlined version for a browser used on mobile devices.
* Simplifies the process of providing different interfaces to the same functionality
* Ease of maintenance for web applications
* More productive use of programming resources due to specialization. Some members of the team can focus on the data and logic component (model) while others focus on the user interface (view).  


The MVC pattern is particularly useful in applications where the same data may need to be represented in different ways. An example of this is a web-based catalog that offers a different interface for a desktop web browser and a more streamlined version for a browser on a mobile device.
* Additional benefits of the MVC pattern include:
** Applications that have a ''cleaner'' design. Key functionality is found in well known and clearly-defined components.
** Increased code reuse and code that is easier to maintain.
** The MVC pattern prevents the creation of monolithic applications where there is no separation of concerns.
** Less coupling between application components.
** Makes it easier to support multiple browser platforms, e.g. an application can be targeted to both desktop web browsers and mobile devices with the use of different views.
** Simplifies the process of providing different types of interfaces to the same functionality.
** More productive use of programming resources due to specialization. Some members of the team can focus on the data and business logic component (model) while others focus on the graphical user interface (view). Developer team responsibilities can be distributed to better match the capabilities of the team members, e.g. GUI experts can focus on producing an appealing and user-friendly interface without having to worry about data retrieval or navigation flow code.


== Different Implementations ==
== Different Implementations ==


Many frameworks have been created to help in the implementation of the MVC pattern. The existing frameworks span multiple programming languages and platforms. The following table shows a list of different application development frameworks that implement the MVC pattern or are based on it. The table is not all-inclusive but the most popular frameworks are listed.
{| border="1" cellspacing="0" cellpadding="5" align="center"
! Implementation
! Language
! Platform
! Description
|-
| [http://rubyonrails.org/ Ruby on Rails]
| Ruby
| Multiple, including Linux, Mac OS, Windows.
| An open-source framework used to create Ruby-based web applications that follow the MVC pattern.
|-
| [http://struts.apache.org/ Apache Struts]
| Java
| Multiple
| An open-source implementation of the Model 2 specification. Uses Java Server Pages and Java Beans to implement web applications that follow the MVC pattern.
|-
| [http://www.asp.net/mvc/ ASP.NET MVC]
| C#, VB.NET
| Windows
| A [http://www.microsoft.com Microsoft] product for the development of web applications that follow the MVC pattern. Currently a there is no cost for using ASP.NET MVC.
|-
| [http://developer.apple.com/tools/webobjects/ WebObjects]
| Java
| Mac OS
| A set of tools offered by [http://www.apple.com Apple Computer] for the development of Java-based web applications.
|-
| [http://java.sun.com/javaee/javaserverfaces/ JavaServer Faces]
| Java
| Multiple
| A J2EE standard for server-side user interfaces.
|-
| Service to Worker Pattern for J2EE applications.
| Java
| Multiple
| Intended for Web-based desktop applications, i.e. applications with only one user [18].
|-
| [http://tapestry.apache.org/ Tapestry]
| Java
| Multiple
| Open-source framework for web applications in Java.
|-
| [http://www.computing.dcu.ie/~rbarrett/software.html#openMVC OpenMVC]
| Java, C#
| Multiple, including Microsoft .NET
| An open source framework with versions for both .NET and Java. OpenMVC uses five tiers to implement an architecture that is based on MVC. The five tiers are: the client, the presentation logic layer, the business logic layer, the data abstraction layer, and the database [6].
|-
| [http://mav.sourceforge.net/ Maverick]
| Java, .NET, PHP
| Multiple
| Mainly for Java web development.
|-
| Model View Presenter (MVP)
| C#, VB.NET
| Windows
| A pattern inspired by the MVC, widely used on applications written for ASP.NET.
|}
<br/>
== Resources ==
:[http://www.ruby-lang.org/en/ Ruby Programming Language]


In addition to the implementations of MVC already mentioned the following applications implement a version of MVC or a framework that is based on it.
:[http://rubyonrails.org/ Rails]


* [http://developer.apple.com/tools/webobjects/ WebObjects], a set of tools offered by [http://www.apple.com Apple Computer] for the development of Java-based web applications.
:[http://java.sun.com/ Java]


* [http://java.sun.com/javaee/javaserverfaces/ JavaServer Faces], a J2EE standard for server-side user interfaces.
:[http://struts.apache.org/ Apache Struts]


* Service to Worker Pattern for J2EE applications, intended for Web-based desktop applications, i.e. applications with only one user [18].
:[http://www.asp.net/ ASP.NET]


* OpenMVC, open source framework used both in .NET and Java applications.
:[http://www.asp.net/mvc/ ASP.NET MVC]


* [http://mav.sourceforge.net/ Maverick], is mainly for Java web development but there also are versions for .NET and PHP.
:[http://martinfowler.com/articles/enterprisePatterns.html Martin Fowler - Patterns in Enterprise Software]


* Model View Presenter (MVP), not a specific technology but another patter inspired by the MVC. The MVP pattern is widely used on applications written in ASP.NET.


== References ==
== References ==
Line 59: Line 138:
[5] Developer - WebObjects. 2009, http://developer.apple.com/WebObjects/.
[5] Developer - WebObjects. 2009, http://developer.apple.com/WebObjects/.


[6] BARRETT, R. AND DELANY, S.J. 2004. OpenMVC: a non-proprietry component-based framework for web applications. In WWW Alt. '04: Proceedings of the 13th international World Wide Web conference on Alternate track papers \& posters, New York, NY, USA, ACM, New York, NY, USA, 464-465.
[6] BARRETT, R. AND DELANY, S.J. 2004. OpenMVC: a non-proprietry component-based framework for web applications. In WWW Alt. '04: Proceedings of the 13th international World Wide Web conference on Alternate track papers & posters, New York, NY, USA, ACM, New York, NY, USA, 464-465.


[7] BURBECK, S. 1997. Applications Programming in Smalltalk-80(TM): How to use Model-View-Controller (MVC). 2009, http://st-www.cs.illinois.edu/users/smarch/st-docs/mvc.html.
[7] BURBECK, S. 1997. Applications Programming in Smalltalk-80(TM): How to use Model-View-Controller (MVC). 2009, http://st-www.cs.illinois.edu/users/smarch/st-docs/mvc.html.


[8] CURRY, E. AND GRACE, P. 2008. Flexible Self-Management Using the Model-View-Controller Pattern. IEEE Software 25, 84-90. http://search.ebscohost.com/login.aspx?direct=true&db=aph&AN=32187572&site=ehost-live&scope=site.
[8] CURRY, E. AND GRACE, P. 2008. Flexible Self-Management Using the Model-View-Controller Pattern. IEEE Software 25, 84-90.  


[9] FOWLER, M. 2006. GUI Architectures. http://www.martinfowler.com/eaaDev/uiArchs.html.
[9] FOWLER, M. 2006. GUI Architectures. http://www.martinfowler.com/eaaDev/uiArchs.html.


[10] FREEMAN, E., FREEMAN, E., SIERRA, K. AND BATES, B. 2004. Head First Design Patterns. O'Reilly Media, Inc., .
[10] FREEMAN, E., FREEMAN, E., SIERRA, K. AND BATES, B. 2004. Head First Design Patterns. O'Reilly Media, Inc.


[11] GAMMA, E. 1995. Design patterns: elements of reusable object-oriented software Addison-Wesley, Reading, Mass.
[11] GAMMA, E. 1995. Design patterns: elements of reusable object-oriented software Addison-Wesley, Reading, Mass.


[12] HANSEN, S. AND FOSSUM, T.V. 2005. Refactoring model-view-controller. J.Comput.Small Coll. 21, 120-129. .
[12] HANSEN, S. AND FOSSUM, T.V. 2005. Refactoring model-view-controller. J.Comput.Small Coll. 21, 120-129.


[13] KRASNER, G.E. AND POPE, S.T. 1998. A Description of the Model-View-Controller User Interface Paradigm in the Small-talk-80 System. 1, 26-49. .
[13] KRASNER, G.E. AND POPE, S.T. 1998. A Description of the Model-View-Controller User Interface Paradigm in the Small-talk-80 System. 1, 26-49.


[14] SAM RUBY, THOMAS, D. AND DAVID HEINEMEIER HANSSON. Agile Web Development with Rails Pragmatic Bookshelf, .
[14] SAM RUBY, THOMAS, D. AND DAVID HEINEMEIER HANSSON. Agile Web Development with Rails Pragmatic Bookshelf, .

Latest revision as of 01:43, 29 September 2009

History and Applications of the MVC Pattern

Introduction

The Model View Controller (MVC) is an architectural design pattern for object-oriented software applications. MVC proposes the use of three different types of components to handle core application functionality. Each component has a distinct and specialized responsibility. The components of an MVC application are: a model, a view, and a controller.

  • The model handles the data which is used by the application. The functionality provided by the model includes retrieving data from its source, usually a relational database, and saving such data once it has changed. The model also enforces the business logic needed to preserve the validity of the data.
  • The view handles the presentation of the data or portions of it in a way that is accessible to the user, usually a Graphical User Interface (GUI). The view is solely concerned with the display of the data and does not perform any validation or business logic.
  • The controller is in charge of processing the interaction between the user and the application. The controller determines which model methods should be invoked in response to user actions. Once data is delivered by the model, the controller also determines which view should display it. In the case of web applications, the controller is where navigation logic is processed [10, 15].

The following diagram illustrates a typical scenario for a web application implemented using the MVC pattern.

History

The MVC pattern was first proposed by "Trygve Reenskaugh in 1979 and implemented by Jim Althoff for Smalltalk-80 [8]." The first implementation of MVC took place at the Xerox PARC research lab as part of the Smalltalk-80 user interface [7]. Smalltalk-80 was a highly interactive graphical user interface which became the precursor of the Apple Lisa and later the Macintosh. The principles of MVC have largely influenced the software developed for the Mac.

The MVC was originally conceived for the implementation of interactive desktop applications with a graphical user interface. Other than the work on Smalltalk and Apple, MVC did not enjoy much popularity in subsequent years. The advent of the web changed things. Initial web applications were written with little or no separation of concerns. A typical web application would combine presentation, business, and data retrieval logic on a single file of code. As applications became more complex, maintenance issues became apparent. Developers started looking for ways to better structure web applications, which resulted in the emergence of the MVC pattern as a very popular choice to provide a solution.

One of the first widely used applications of the MVC pattern on web applications appeared as part of the Java Server Pages (JSP) specification, known as Model 2 [2, 10]. Model 2 implements MVC in Java using Servlets, Java Beans, and JSPs. Model 2 is perhaps the most popular implementation of the MVC pattern currently in use.

Another very popular Java implementation of the MVC pattern is the open source project Apache Struts. Struts provides the necessary framework to write web applications in Java following the MCV design pattern [1] using Java Server Pages (JSP) and Java Servlets as the main building blocks. The Struts framework has been in wide use since 2001 when the Jakarta project gained popularity [18].

Following the Java implementations came Microsoft's MVC versions for the Active Server Pages platform [16]. Initially MVC was proposed as part of the Microsoft Enterprise Library. The enterprise library is a set of suggested best practices along with standard code targeted to .NET Framework developers. Recently Microsoft has turned its MVC implementation into a full-fledged product, integral part of the latest version of ASP.NET and Visual Studio .NET [3].

Currently one of the most popular implementations of MVC can be found as part of the Rails framework for web-based development using Ruby. MVC is at the heart of Ruby on Rails and its principles determine how web applications written in the framework are structured [14]. Ruby on Rails is one of the factors that has largely contributed to the popularity of the Ruby language.

Benefits and Applications

  • The main benefit of the MVC pattern is that it separates the data, application, and presentation logic from each other. Applications built following the MVC pattern result in an implementation that is more cohesive and less coupled. The essential functionality needed for an application's functionality is located in distinct components that specialize in one of the three core functions.
  • The MVC pattern is an ideal choice for structuring web applications, where high interactivity is expected. MVC is particularly useful in applications where the same data must be presented in different ways. An example of this is a web-based catalog that offers a different interface for a desktop web browser and a more streamlined version for a browser used on mobile devices.
  • Additional benefits of the MVC pattern include:
    • Applications that have a cleaner design. Key functionality is found in well known and clearly-defined components.
    • Increased code reuse and code that is easier to maintain.
    • The MVC pattern prevents the creation of monolithic applications where there is no separation of concerns.
    • Less coupling between application components.
    • Makes it easier to support multiple browser platforms, e.g. an application can be targeted to both desktop web browsers and mobile devices with the use of different views.
    • Simplifies the process of providing different types of interfaces to the same functionality.
    • More productive use of programming resources due to specialization. Some members of the team can focus on the data and business logic component (model) while others focus on the graphical user interface (view). Developer team responsibilities can be distributed to better match the capabilities of the team members, e.g. GUI experts can focus on producing an appealing and user-friendly interface without having to worry about data retrieval or navigation flow code.

Different Implementations

Many frameworks have been created to help in the implementation of the MVC pattern. The existing frameworks span multiple programming languages and platforms. The following table shows a list of different application development frameworks that implement the MVC pattern or are based on it. The table is not all-inclusive but the most popular frameworks are listed.

Implementation Language Platform Description
Ruby on Rails Ruby Multiple, including Linux, Mac OS, Windows. An open-source framework used to create Ruby-based web applications that follow the MVC pattern.
Apache Struts Java Multiple An open-source implementation of the Model 2 specification. Uses Java Server Pages and Java Beans to implement web applications that follow the MVC pattern.
ASP.NET MVC C#, VB.NET Windows A Microsoft product for the development of web applications that follow the MVC pattern. Currently a there is no cost for using ASP.NET MVC.
WebObjects Java Mac OS A set of tools offered by Apple Computer for the development of Java-based web applications.
JavaServer Faces Java Multiple A J2EE standard for server-side user interfaces.
Service to Worker Pattern for J2EE applications. Java Multiple Intended for Web-based desktop applications, i.e. applications with only one user [18].
Tapestry Java Multiple Open-source framework for web applications in Java.
OpenMVC Java, C# Multiple, including Microsoft .NET An open source framework with versions for both .NET and Java. OpenMVC uses five tiers to implement an architecture that is based on MVC. The five tiers are: the client, the presentation logic layer, the business logic layer, the data abstraction layer, and the database [6].
Maverick Java, .NET, PHP Multiple Mainly for Java web development.
Model View Presenter (MVP) C#, VB.NET Windows A pattern inspired by the MVC, widely used on applications written for ASP.NET.


Resources

Ruby Programming Language
Rails
Java
Apache Struts
ASP.NET
ASP.NET MVC
Martin Fowler - Patterns in Enterprise Software


References

[1] Apache Struts Web Application Framework. 2009, http://struts.apache.org/.

[2] Designing Enterprise Applications with the J2EE Platform, Second Edition. 2009, http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html.

[3] ASP.NET MVC : The Official Microsoft ASP.NET Site. 2009, http://www.asp.net/mvc/.

[4] JavaServer Faces Technology. 2009, http://java.sun.com/javaee/javaserverfaces/.

[5] Developer - WebObjects. 2009, http://developer.apple.com/WebObjects/.

[6] BARRETT, R. AND DELANY, S.J. 2004. OpenMVC: a non-proprietry component-based framework for web applications. In WWW Alt. '04: Proceedings of the 13th international World Wide Web conference on Alternate track papers & posters, New York, NY, USA, ACM, New York, NY, USA, 464-465.

[7] BURBECK, S. 1997. Applications Programming in Smalltalk-80(TM): How to use Model-View-Controller (MVC). 2009, http://st-www.cs.illinois.edu/users/smarch/st-docs/mvc.html.

[8] CURRY, E. AND GRACE, P. 2008. Flexible Self-Management Using the Model-View-Controller Pattern. IEEE Software 25, 84-90.

[9] FOWLER, M. 2006. GUI Architectures. http://www.martinfowler.com/eaaDev/uiArchs.html.

[10] FREEMAN, E., FREEMAN, E., SIERRA, K. AND BATES, B. 2004. Head First Design Patterns. O'Reilly Media, Inc.

[11] GAMMA, E. 1995. Design patterns: elements of reusable object-oriented software Addison-Wesley, Reading, Mass.

[12] HANSEN, S. AND FOSSUM, T.V. 2005. Refactoring model-view-controller. J.Comput.Small Coll. 21, 120-129.

[13] KRASNER, G.E. AND POPE, S.T. 1998. A Description of the Model-View-Controller User Interface Paradigm in the Small-talk-80 System. 1, 26-49.

[14] SAM RUBY, THOMAS, D. AND DAVID HEINEMEIER HANSSON. Agile Web Development with Rails Pragmatic Bookshelf, .

[15] SKRIEN, D.J. 2009. The Model-View-Controller Architecture. In Object-Oriented Design Using Java, McGraw-Hill Higher Education, , 234.

[16] WALTHER, S. ASP.NET MVC Framework Unleashed. Sams, .

[17] WALTHER, S. 2008. The Evolution of MVC. .

[18] YAN, N., LEIP, D. AND GUPTA, K. 2005. The use of open-source software in the IBM corporate portal. IBM Systems Journal 44, 419-425.


CSC 517 Fall 2009

Wiki 1b Assignment

Author: Newwolf