MVC: Delegating interface behavior
Today a friend asked me to look over some code he wrote using an MVC framework. One of the first things I noticed was that there was just to much logic going on in some of the views. I would see code that was directing the behavior of the view which is a big no no, we will get to that in a second. In the edit forms for a product I saw logic like this.
You may not realize it but by doing this your actually breaking one of the key concepts of MVC. The view should only concern itself with presentation and it should always look to delegate to the controller for its logic. The reason we do this is to keep modularity by maintaining loose coupling with the controller. A better way of handling the issue above would be to delegate this logic to our controller.
I guess the main point of this entry is to remind us (I make the same mistake) that just because we use a framework doesn't mean your work is done. You still need to be mindful of why you are using it in the first place!
