Вы находитесь на странице: 1из 19

MVC(Model View Controller) Web, Enterprise and Mobile: Seen in Kohana php, .Net, iphone, and Android development.

For BarCamp Cameroon 2010 by Njie-Litumbe.L.Nara


Developer, AfroVisioN Group

The Purpose
Many computer systems rely on retrieving data from a data store and displaying for the user. User changes data and the data is updated to the store Key flow: Data store and User Interface Temptation/But Natural: Tie the Data store and User Interface Problem: 1.The user interface changes more than data store 2.Mixing business logic and presentation

Other consequences
User interface logic tends to change more frequently than business logic, especially in Webbased applications. User interface code tends to be more devicedependent than business logic Application may display the same data in different ways. Separate development effort.

QUESTION

How do I separate Presentation ,Logic and Data for a near-perfect, reliable and future-proof solution?

SOLUTION

Model, View, Controller Model-View-Controller is a fundamental design pattern for the separation of user interface presentation from business logic and data.

What MVC Is
Software Architecture(Engineering) Object Oriented Orderly Code Reuse

History
MVC Is 31 Years Old! Smalltalk-80 (circa 1980) MVC first discussed in 1979 by Trygve Reenskaug MFC (Document/View) Javas Swing Apples Cocoa (Core Data) * MVC is suited for GUI(Graphical User Interface) Development!

MVC whereAlmost Anywhere


More than 10 GUI frameworks (enterprise) More than 15 web-based frameworks Implement MVC(web).
Made popular by Ruby on Rails

Developing applications for iphone and Android phones use the MVC(more tight coupling) design pattern

MODEL
Data Storage/Access Often Data source backed MySQL, MSSQL, Web Service, it doesnt matter Manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). Simply, they represent the data your application manages

VIEW

HTML Templates: All formatting(css,js,jq etc) related code belongs here. The view manages the display of information.

CONTROLLER
* Be concern

Process user inputs, communicate with Models and Views Acts Like a Betweener Much of the applications core logic Invoke model, assign values to views The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

REQUEST

RESPOND

CONTROLLER
-Input Filters(authentication) -Action Dispatching -Output filters(Compression, cache)

MODEL
Data Persistence -Relationships

VIEW
-Presentation -Layout -Graphic Interface

Only I know the DB

Database

Must be Clear.
The Model does not depend on view nor the controller but the controller and view depend on model. Only the model has access to the database Only Controller can request the Model to change state.(the view may ask about Its state). MVC due to its popularity this points have been misrepresented;but the order it tries to bring should be the engineers focus.

Do you know..
With MVC It is easier to look for errors, by knowing the particular file(object) either its a View, Controller or Model than by knowing the line from which the error is coming from? With MVC you can do a design for one app and implement over several different platforms easily. For example the application which was developed at the AVNLab for iphone, and android.It is a clear demo of MVC for mobile. With MVC design pattern dont bother about your language expertise. You would find your self translating from one framework or one mobile phone development plateform to another rather than re-coding. As I moved from Code Igniter to Kohana ;).

Why MVC?
We have seen that with MVC: Good architectural design Code is organized and structured Easy code maintenance Because of abstraction, better strategic positioning of code will minimize the hunt for places to change Easy to extend and grow Modify parent classes, drop in new controller, etc. Ease of Testing Model can be tested separately from the user interface.

Supports multiple views: Because the view is separated from the model and there is no direct dependency from the model to the view, the user interface can display multiple views of the same data at the same time. For example, multiple pages in a Web application may use the same model objects. Accommodates change: User interface requirements tend to change more rapidly than business rules. Users may prefer different colors, fonts, screen layouts, and levels of support for new devices such as cell phones or PDAs. Because the model does not depend on the views, adding new types of views to the system generally does not affect the model. As a result, the scope of change is confined to the view. 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. Development of the various components can progress in parallel: Once the interface between the components is clearly defined. The designer can be doing the interface while the developer does the logic; It is merged later.

EXAMPLE CODE

Implementing Model View Controller in Kohanaphp. Simple Information collection form: Demo of MVC for Barcampcameroon 2010:http://njielitumbe.livejournal.com Implementing Model view Controller in ASP.NET
http://msdn.microsoft.com/en-us/library/ff647462.aspx

* Implementing Model View Controller for iphone and Android with Jqtouch(written by mambenanje at AfroVisioNgroup lab in about 3 hours) - http://www.packtpub.com/article/build-iphone-android-ipadapplications-jqtouch-jquery

REFERENCES
http://msdn.microsoft.com/enus/library/ff649643.aspx With 6,203,493 and still counting, Google is your Friend : http://www.google.com/search?hl=en&q=mvc Afrovisiongroup:www.afrovisiongroup.com Wikipedia: http://en.wikipedia.org/wiki/Model%E2%80%93view %E2%80%93controller

THANK YOU

Вам также может понравиться