Yesterday, an article by Shneiderman on “visualization mantra” provoked me to think about “software development mantra”. For last 3 years, I am involved with the development of Memento – an online bibliography management solution. During this time, I learnt a lot about software development in general and about MVC architecture in particular. To some extend, the credit also goes to CakePHP as it forces MVC architecutre (Model-View-Controller) on your software. CakePHP helped me to gain a deep understanding of MVC architecutre and appreciate it. So here is the essense of what I learnt in last three years – my software development mantra
Software Development mantra
“Thick Models, thin Controller, simple views, lot of elements“
— Ritesh Agrawal
Note: I haven’t searched enough to see if anyone else proposed any such mantra. Also I do not claim that this is an original mantra as I have seen few people mentioning “thick models” in CakePHP forum. So I leave upto to figure out to whom you should give credit.
So whenever possible, try to implement data manipulation logic in models. Controller should only act as a connection between view and model, transferring data between the two. Whenever you start feeling that the controller is becoming too big and doing lot of data manipulation and data query, think of how you can push that code onto related model. The benefit of having most of the data manipulation code in model is the ability to use those functions from another controller.
Another principle that in conjunction with the above mantra can help in better software development is DRY (Don’t repeat yourself). If you will follow DRY principle you will end up implementing thick models, thin controllers, simple views, and lot of elements.