I usually implement MVC as follows:
View - receives data from the controller and generates an output signal. Usually only display logic should be displayed here. For example, if you want to take an existing site and create a version for mobile / iPhone, you must do this by simply replacing the views (provided that you need the same functionality).
Model - wrap access to data in models. In my applications, all of SQL lives at the model level; direct data access is not allowed in views or controllers. As Eli points out in another answer, the idea is to (at least partially) isolate your controllers / views from changes in the database structure. Models are also a good place to implement logic such as updating the “last modified” date whenever a field changes. If the main data source for your application is an external web service, consider whether this is being ported to the model class.
Controllers - Used to glue models and views together. Implementing application logic here, validating forms, transferring data from models to views, etc.
For example, in my applications, when a page is requested, the controller will extract all the data from the models and transfer it to the view to create the page that the user sees. If this page was a form, the form can be submitted, the controller processes the validation, creates the necessary model and uses it to save the data.
If you follow this method, the models will become quite versatile and reusable. Your controllers have a manageable size and complexity, since access to data and their display have been removed respectively in Models and Views, and your views should be simple enough so that the developer (with a little preparation) can understand them.
Jim ohalloran
source share