Written on March 8th, 2010 at 9:15 pmby Arun Vishnu

0 Comments

Several problems can arise when applications contain a mixture of data access code, business logic code, and presentation code. Such applications are difficult to maintain, because interdependencies between all of the components cause strong ripple effects whenever a change is made anywhere. High coupling makes classes difficult or impossible to reuse because they depend on so many other classes. Adding new data views often requires re-implementing or cutting and pasting business logic code, which then requires maintenance in multiple places. Data access code suffers from the same problem, being cut and pasted among business logic methods. Also it is hard to use multiple views of the same data.

The Model-View-Controller design pattern solves these problems by decoupling data access, business logic, and data presentation and user interaction.

Model–View–Controller (MVC) is an architectural pattern used in software engineering. The pattern isolates "domain logic" (the application logic for the user) from input and presentation (GUI), permitting independent development, testing and maintenance of each.

The MVC pattern is most commonly used to create interfaces for software applications, and, as the name implies, consists of three elements:

The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.

  1. The View is the information that is being presented to a user.

  2. The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.

Architecture

image

  1. View tells to controller handle user inputs

  2. Controller changes model state

  3. Model tells view to update itself

  4. View reads state information from model and updates itself.

Comparison with the Three-tier architecture

The three-tier architecture may seem similar to the MVC concept; however, topologically they are different. A fundamental rule in a three-tier architecture is the client tier never communicates directly with the data tier; in a three-tier model all communication must pass through the middleware tier. Conceptually the three-tier architecture is linear. However, the MVC architecture is triangular.

image

Share

Most Commented Posts

, ,

Be the first to start a conversation

Leave a Reply