With the introduction of joomla 1.5.x, I was very excited to learn the new architecture implemented. With the increasing popularity of Joomla 1.5.x I could not stop myself teach myself the new Joomla MVC pattern.
MVC stands for Model View Controller
MVC is an architectural pattern used in software engineering. The model-view-controller solves this problem by decoupling data access and business logic from data presentation and user interaction, by introducing an intermediate component: the controller.
In other words , to organize a computer applications that present lots of data to the user, one often wishes to separate data (model) and user interface (view) , so that changes to the user interface (ie Front End Design) do not impact the data handling (ie Backend), and that the data can be reorganized without changing the user interface.
MVC was originally developed to map the traditional input, processing, output roles into the GUI realm:
Input –> Processing –> Output
Controller –> Model –> View
the Model-View-Controller (MVC) pattern organizes and separates software into three distinct roles:
- The Model encapsulates your application data, application flow, and business logic.
- The View extracts data from the Model and format it for presentation
- The Controller direct application flow and receive input and translates it for the Model and View.
The model is the part of the component that encapsulates the application’s data. It will often provide routines to manage and manipulate this data in a meaningful way in addition to routines that retrieve the data from the model. In our case, the model will contain methods to add, remove and update information about the books in the database. It will also contain methods to retrieve the list of books from the database. In general, the underlying data access technique should be encapsulated in the model. In this way, if an application is to be moved from a system that utilizes a flat file to store its information to a system that uses a database, the model is the only element that needs to be changed, not the view or the controller.
The view is the part of the component that is used to render the data from the model in a manner that is suitable for interaction. For a web-based application, the view would generally be an HTML page that is returned to the data. The view pulls data from the model (which is passed to it from the controller) and feeds the data into a template which is populated and presented to the user. The view does not cause the data to be modified in any way, it only displays data retrieved from the model.
The controller is responsible for responding to user actions. In the case of a web application, a user action is a page request. The controller will determine what request is being made by the user and respond appropriately by triggering the model to manipulate the data appropriately and passing the model into the view. The controller does not display the data in the model, it only triggers methods in the model which modify the data.
When we implement MVC, we face in more complex codes. The Model, View, and Controller are never captured in single classes, but are instead implemented as closely-related groups of objects, where each group performs one specific MVC task.