Publicidad
Publicidad

Más contenido relacionado

Publicidad
Publicidad

MVC

  1. MVC Reducing software project failures by design pattern(MVC) Prepared By : Iman Mehmandoust
  2. Contents • MVC Definition • MVC Example • Model • View • Controller • Software Failures • Why MVC? • Clarity of design • Efficient modularity • Multiple views • Powerful user interfaces • Ease of growth Tuesday, June 9, 2015
  3. Definition • The Model-View-Controller (MVC) pattern, originally formulated in the late 1970s • MVC is an architectural pattern used in software engineering. • MVC is a software design pattern that separates application logic from presentation. In this case MVC has a front-end developer and a back-end developer to work with the same system without interfering or editing there files by their permeations • The MVC pattern is most commonly used to create interfaces for software applications, and, as the name implies, consists of three elements:(Model View Controller) Tuesday, June 9, 2015
  4. • The pattern’s title is a collation of its three core parts: Model, View, and Controller. A visual representation of a complete and correct MVC pattern looks like the following diagram: Tuesday, June 9, 2015
  5. Model • The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database. Tuesday, June 9, 2015
  6. View • The View is the information that is being presented to a user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of "page". Tuesday, June 9, 2015
  7. Controller • 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 Tuesday, June 9, 2015
  8. Example: A simple way to think of this would be to consider the following: • A user interacts with the view - by clicking on a link or submitting a form. • The Controller handles the user input, and transfers the information to the model • The Model receives the information and updates it's state (adds data to a database or database interaction, or perform complex calculation for example, calculates todays date) • The View checks the state of the Model and responds accordingly to the requester or user (listing the newly entered data, maybe) • The View waits for another interaction from the user. Tuesday, June 9, 2015
  9. Software Failures • Difficult to use the data outside that object. • Hard to use multiple views of the same data. • Difficult to synchronize multiple view of the same data. • Hard to change the UI, when UI and data are locked in the same object. Tuesday, June 9, 2015
  10. Why MVC? Just by breaking the program down into the three MVC components, one gains many advantages. These are the most significant ones I've found through my own experience: • Clarity of design: the public methods in the model stand as an API for all the commands available to manipulate its data and state. this trait makes the entire program easier to implement and maintain. • Efficient modularity: Changes to one aspect of the program aren't coupled to other aspects, eliminating many nasty debugging situations. Also, development of the various components can progress in parallel, once the interface between the components is clearly defined. Tuesday, June 9, 2015
  11. • Multiple views: the application can display the state of the model in a variety of ways, and create/design them in a scalable, modular way. This comes up in games, with a cockpit and a radar view, and in my research applications, where I have a view to display the state of the model and another view that collects data, calculates statistics, then to saves the data to disk. Both views are using the same data, they just use the information differently. During the development process, I usually start out with a text based view, which just prints out the data that the model is generating. Later, as I create new views, I can use the text based view to verify the performance of the new views. • Powerful user interfaces: using the model's API, the user interface can combine the method calls when presenting commands to the user. Macros can be seen as a series of "standard" commands sent to the model, all triggered by a single user action. This allows the program to present the user with a cleaner, friendlier interface. Tuesday, June 9, 2015
  12. • Ease of growth: controllers and views can grow as the model grows; and older versions of the views and controllers can still be used as long as a common interface is maintained (the text view just mentioned is an example). For instance, if an application needs two types of users, regular and administrator, they could use the same model, but just have different controller and view implementations. This is related to the similarity with the client/server architecture - where the new views and servers are analogous to the clients. Tuesday, June 9, 2015
  13. References • Definition of MVC: https://ellislab.com/codeigniter/user-guide/overview/mvc.html • MVC Advantages: http://cristobal.baray.com/indiana/projects/mvc2.html • E-Book Model-View-Controller: A Design Pattern for Software June 2004 Tuesday, June 9, 2015
Publicidad