Class 9 – MVC Architecture
Posted: April 26th, 2009 | Author: amos | Filed under: php | Tags: class 9, controller, model, mvc, view | No Comments »MVC architecture is a growing trend in software development of all kinds, including for the web. If you can master object-oriented programming combined with MVC architecture, you can consider yourself to be a very knowledgeable developer.
This architecture divides the code involved in any project into three parts: Model, View, and Controller. It’s important to bear in mind that the idea of dividing a project into these three parts is a concept. How that concept should actually be implemented in practice depends on who you’re talking to, what language(s) you are programming in, as well as the framework you are using, if any.
M is for Model, V is for View, and C is for Controller.
The Model is the part of the code that deals directly with the database. So all the code that does the database CRUD (create, read, update, delete) functions, as well as any other code that makes direct queries to the database should be considered part of the Model. Any time any code in any application you are building needs to interact with the database in any way, it has to do that by calling functions in the Model.
The View is the part of the code that creates the interface that the user sees. For web development, the View consists mostly of the XHTML, CSS, Javascript, and any other client-side technologies that create the actual interface of the web site. The view is the sort-of template that is then filled in with data that comes from the Model.
The Controller is the sort of brains of the operation. It is the glue that links the Model, the View, and the user together. The controller’s main function is to figure out what the user is trying to do, and to then use the Model to get the data that is necessary to do that, and then use the View to display that data to the user in a nicely designed page.
Leave a Reply