Coding Practices
Thursday, February 25, 2010
Posted by Rowan
Everyone knows that there is more then one way to skin a cat. In terms of application development, there are usually several hundred ways of accomplishing the same task. Because of this, one could be tempted to take the 'quick and easy' route, opting to 'patch' the system whenever business logic changes.
I learnt my lesson with the 'quick and easy' route a long while back, realising that it is better to spend more time on the design of the program rather then just getting the job done.
Remember in programing, it pays to be conservative. By sticking to coding standards and architectural rules, you will most likely end up with a more flexible, portable and manageable application.
Widely used in many programing / scripting language frameworks is the Model-View-Controller (MVC) architectural pattern. When properly implemented, the MVC helps separate domain logic (or raw data), requests for that data and the user interface, into 3 separate entities.
The Model:
The model is the domain specific representation of data which is used by the application. If we were developing a simple web application which required a connection to the database, this is the place we the query would be made, returning only the raw data. The Model does not define were a connection is made or when the connection occurs, simply holds the logic for retrieving the raw data.
The View:
The view is the data presentation layer within the model. The view does nothing more then display the raw data collected at the model. In a simple terms a view could be a html or XML template used to display data from the model.
The Controller:
The controller is the director, or router of requests for information. In a web application the controller handles requests sent from the browser and directs the request to the appropriate model / view.
A great way of sampling the MVC in practice is to review some of the frameworks that are built upon it. We have several applications based on the CodeIgniter PHP framework, but there are many other similar PHP frameworks out there that are MVC based. Another good sample of the MVC in action is Joomla, a very popular Open Source Content Managment System (CMS).



I learnt my lesson with the 'quick and easy' route a long while back, realising that it is better to spend more time on the design of the program rather then just getting the job done.
Remember in programing, it pays to be conservative. By sticking to coding standards and architectural rules, you will most likely end up with a more flexible, portable and manageable application.
Widely used in many programing / scripting language frameworks is the Model-View-Controller (MVC) architectural pattern. When properly implemented, the MVC helps separate domain logic (or raw data), requests for that data and the user interface, into 3 separate entities.
The Model:
The model is the domain specific representation of data which is used by the application. If we were developing a simple web application which required a connection to the database, this is the place we the query would be made, returning only the raw data. The Model does not define were a connection is made or when the connection occurs, simply holds the logic for retrieving the raw data.
The View:
The view is the data presentation layer within the model. The view does nothing more then display the raw data collected at the model. In a simple terms a view could be a html or XML template used to display data from the model.
The Controller:
The controller is the director, or router of requests for information. In a web application the controller handles requests sent from the browser and directs the request to the appropriate model / view.
A great way of sampling the MVC in practice is to review some of the frameworks that are built upon it. We have several applications based on the CodeIgniter PHP framework, but there are many other similar PHP frameworks out there that are MVC based. Another good sample of the MVC in action is Joomla, a very popular Open Source Content Managment System (CMS).
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
Coding practices
. Follow any responses to this post through RSS. You can leave a response, or trackback from your own site.
Subscribe to:
Post Comments (Atom)
Post a Comment