25
What is MVC?
M - Model = This is the portion that DOES the work.
C - Controller = This is the portion that Controls what happens.
V - View = This is the actual user interface that the user accesses and views.
With Xoops we have a system that for years basically has consisted of a template that is loaded with values from a module. In other words we are already 2/3rds the way there with a standard module.
In my "advanced" java class our instructor explained this model in a manner where each component of an MVC design should theoretically setup in a manner that it can be pulled out of the program and replaced without impacting the program.
What this means for instance is the Model did all of the actual work. It communicates to the database, validates the data, or whatever other job the module is supposed to do. Such as calculate a date or whatever. When writing a Model it is a good idea to have it be able to stand on its own. It should NOT depend on anything being returned to it from the controller or from the view. It should only act on the data sent to it and return any results back to the calling procedure.
The view should also be able to work on its own. It should present data to the user or retrieve data from the user. In my Java class we had to have a console based View and a GUI based view. This entitled that the View wasn't directly dependent on any other component. It only showed what it was told to show and only returned what was requested.
The controller is the brain of the system. It will take input from the view, send it to the model to process and display results back to the view. In my Java class we had to build 2 different controllers to do totally different things with our Model and our View. This allowed us to have two totally different, but similar, programs by just changing the controller but using the original view and original model.
Separating your program into these three components helps in many ways. You can reuse your code easily in other modules and you could actually build a Model that could be used by many different programs or modules like a framework of a sort. You could also make it easier to be compatible with other versions of xoops by insuring all of your xoops related code is in the model. A service provider could be written much easier for xoops 2.6 as well.
Another thing it helps with is testing. phpUnit can test functions much easier in an MVC environment. It can really test the Model objects well since they are designed to be self contained. The controller can also be tested easier because you should be able to run controller functions without a view. The view may not need to be unit tested and may not be able to be unit tested.
Regardless to what some developers might believe MVC is here to stay. It makes sense and in the long run will make a developers life much easier by simplifying the code.
Rodney