Sie sind auf Seite 1von 7

MVC Architecture

MVC was originally developed to map the traditional input, processing, output roles into the GUI realm: Input > Processing > Output Controller > Model > View The main aim of the MVC architecture is to separate the business logic and application data from the presentation data to the user. ModelViewController (MVC) is a design pattern for computer user interfaces that divides an application into three areas of responsibility: 1. the Model: the domain objects or data structures that represent the application's state. 2. the View, which observes the state and generates output to the users. 3. the Controller, which translates user input into operations on the model. The model captures the domain logic of the application those actions a user might want to request with a strong separation from the way that the user requests them and sees the results. The latter are managed by the view and controller together, under the constraint that input usually does not trigger output directly. Instead, the model triggers output when it detects that an action has caused a significant change in its state.

Model: It handles data processing and database works part. Model processes events sent by controller. After processing these events then it sends processed data to controller (thus, controller may reprocess it) or directly to view side. View:

View prepares an interface to show to the user. Controller or model tells view what to show to the user. Also view handles requests from user and informs controller. Controller: Lets say controller is like brain of the system. That is right. Because it processes every request, prepares other parts of the system like model and view. Then the system determines what to do by controllers commands. Uses of MVC design pattern. 1. They are resuable : When the problems recurs, there is no need to invent a new solution, we just have to follow the pattern and adapt it as necessary. 2. They are expressive: By using the MVC design pattern our application becomes more expressive. 1) Model: The model object knows about all the data that need to be displayed. It is model who is aware about all the operations that can be applied to transform that object. It only represents the data of an application. The model represents enterprise data and the business rules that govern access to and updates of this data. Model is not aware about the presentation data and how that data will be displayed to the browser. 2) View : The view represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain the contents and renders it. The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we can say that it is the responsibility of the of the view's to maintain the consistency in its presentation when the model changes. 3) Controller: Whenever the user sends a request for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. In GUIs, the views and the controllers often work very closely together.

Model: A model is an object that manages information. It calculates, sorts, stores, retrieves, simulates, emulates, converts, and does just about anything else you can think of doing to information. The model by itself has no visual representation. It includes the validation rules. It does not know how to display the information it contains. As MVC architecture the model information can be divided into two categories: i) Domain information Model ii) Application information Model I) Domain information Model: Domain information model includes that information concerned with the problem domain. For example, if we have an airline reservation application, then flight schedules, prices, seating arrangements, and credit card numbers would all be domain information. II) Application information Model: Application information model is any information that is used by the application but is not part of the problem domain. In the airline reservation example, error messages are part of the application information.

View: The view provides a visual representation of the information contained in the model. As the information in the model changes, the view should automatically change. A view depends on the information contained within its model. Examples of views are input fields, text editors, and even entire windows. Controller: Whenever the user sends a request for something then it always go through the controller. The Controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user.

View to model communication The views know of the model and will interact with the model. If a button is clicked an action message might be sent to a model object in order to get something done. If a new value is typed into an entry field an update message might be sent to a model object in order to give it its new value. If a value is needed for a display an enquiry message might be sent to a model object in order to get a value. Model (and controller) to view communication Whenever some aspect of the model changes; an aspect that is displayed in a view. Model and controller to communicate with view via events. Using graphical components a list box, an entry field or a radio button these view components will receive event notifications such as needs contents, or clicked. The events will often come from the controller. Views register handlers for the events they wish to

handle. Advantages of MVC Architecture: 1. They are reusable: When the problem recurs, there is no need to invent a new solution; we just have to follow the pattern and adapt it as necessary. 2. They are expressive: By using the MVC design pattern our application becomes more expressive. 3. Easier support for new types of clients: To support a new type of client, you simply write a view and controller for it and wire them into the existing enterprise model.

Example of MVC architecture: 1. When the user Log In on the login page, a request is sent to the servlet handler. 2. The servlet handler dispatches the request to the appropriate control class. In this case, Login control. 3. The Control performs the action requested by the user on the Model; in this case the Login Model. 4. The Model returns a response; in this example, a successful login message. 5. The Control either redirects to another page or returns to the same page with new data since the Model has been updated. In this case, the Control redirects to the MyPage. 6. The Interpreter gets the HTML for the page requested by the Control from the appropriate View, in this case the MyPage View 7. The View returns the HTML for the page. 8. The Interpreter sends the HTML for the page back to the browser. Difference between Model 1 and Model 2 architecture: Features of MVC1: 1. Html or jsp files are used to code the presentation. To retrieve the data JavaBean can be used. 2. In mvc1 archictecture all the view, control elements are implemented using Servlets or Jsp. 3. In MVC1 there is tight coupling between page and model as data access is usually done using Custom tag or through java bean call. Features of MVC2: 1. The MVC2 architecture removes the page centric property of MVC1 architecture by

separating Presentation, control logic and the application state. 2. In MVC2 architecture there is only one controller which receives all the request for the application and is responsible for taking appropriate action in response to each request.

Zend Framework
Zend Framework is an open source, object oriented web application framework for PHP 5. Zend Framework is often called a 'component library', because it has many loosely coupled components that you can use more or less independently. Zend Framework also provides an advanced Model-View-Controller (MVC) implementation that can be used to establish a basic structure for your Zend Framework applications. A full list of Zend Framework components along with short descriptions may be found in the components overview. This QuickStart will introduce you to some of Zend Framework's most commonly used components, including Zend_Controller, Zend_Layout, Zend_Config, Zend_Db, Zend_Db_Table, Zend_Registry, along with a few view helpers.

Features : Zend Framework features include: All components are fully object-oriented PHP 5 and are E_STRICT compliant Use-at-will architecture with loosely coupled components and minimal interdependencies Extensible MVC implementation supporting layouts and PHP-based templates by default Support for multiple database systems and vendors, including MariaDB, MySQL, Oracle, IBM DB2, Microsoft SQL Server, PostgreSQL, SQLite, and Informix Dynamic Server Email composition and delivery, retrieval via mbox, Maildir, POP3 and IMAP4 Flexible caching sub-system with support for many types of backends, such as memory or a file system. What is the Zend Framework, exactly? The Zend Framework: Is based on PHP Is object-oriented Uses the MVC paradigm Has open source contributors Has contributors who take responsibility for the fact that their code is not the intellectual property of someone else

It also aims to make your programming life easier, not just in general by instituting the MVC pattern, but also for specific things you tend to do all the time, like access databases or output to a PDF file. (OK you probably don't output to a PDF file all the time. But I'll bet you would if it were easier.) Zend Framework components include: Zend_Controller This module provides the overall control for the application. It translates requests into specific actions and makes sure they get executed.

Zend_Db This is based on PHP Data Objects (PDO) and provides access to databases in a generic way. Zend_Feed This makes it easy to consume RSS and Atom feeds. Zend_Filter This provides string-filtering functions, such as isEmail() and getAlpha(). Zend_InputFilter To Zend_Filter, this is designed to work with arrays such as form inputs. Zend_HttpClient This enables you perform HTTP requests easily. Zend_Json This enables you to easily translate PHP objects into JavaScript Object Notation, and viceversa. Zend_Log This provides general-purpose logging functionality. Zend_Mail This enables you to send text and multipart MIME email. Zend_Mime This is used by Zend_Mail to help decode MIME messages. Zend_Pdf This enables you to create new PDF documents, and load and edit existing PDF documents. Zend_Search This enables you to perform sophisticated searches on your own text. For example, you can build a search engine that returns results based on relevancy or other factors. Zend_Service Contains several submodules that provide easy access to many popular web service APIs, such as those provided by Amazon, Yahoo, Twitter, and Flicker. Zend_View This handles the view portion of the MVC pattern. Zend_XmlRpc This enables you to easily create an XML-RPC server and client.

Das könnte Ihnen auch gefallen