CSC/ECE 517 Fall 2009/wiki1b 13 a1: Difference between revisions
Line 13: | Line 13: | ||
The following diagram illustrates a typical scenario for a web application implemented using the MVC pattern. | The following diagram illustrates a typical scenario for a web application implemented using the MVC pattern. | ||
[[Image:MVC_Diagram. | [[Image:MVC_Diagram.JPG]] | ||
''' | ''' | ||
Revision as of 23:34, 27 September 2009
History and Applications of the MVC Pattern
Introduction
The Model View Controller (MVC) is an architecture 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, 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, however. 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 and maintenance issues became apparent, developers started looking into ways to better structure web applications. The MVC pattern emerged as a very popular choice to provide a solution. MVC is not really a new idea as it may appear, it is an idea that has existed for quite a while and for which new applications have been found.
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. 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 basically 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 should be structured [14].
Benefits and Applications
The main strength of the MVC pattern is that it separates the data, application, and representation logic from 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 specialize in one of these core functions.
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 used on mobile devices.
Additional benefits of the MVC pattern include:
- Increase code reuse
- 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).
Different Implementations
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.
- WebObjects, a set of tools offered by Apple Computer for the development of Java-based web applications.
- JavaServer Faces, a J2EE standard for server-side user interfaces.
- Service to Worker Pattern for J2EE applications, intended for Web-based desktop applications, i.e. applications with only one user [18].
- OpenMVC, open source framework used both in .NET and Java applications.
- Maverick, is mainly for Java web development but there also are versions for .NET and PHP.
- Model View Presenter (MVP), not a specific technology but another pattern inspired by the MVC. The MVP pattern is widely used on applications written in ASP.NET.
Resources
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