Model-View-Controller Design Patter for Coders

A lot of ideas and modern day solutions to software engineering was originally coined by Smalltalk programmers. Same goes for the concept most widely preferred among design patterns, the Model-View-Controller.

The actual onus of inventing this design pattern goes to one Trygve Reenskaug way back in 1979 and unlike other examples or ideas on this topic, I am going to reference his exact explanation and try to make it easier for you to understand.

By the way, this is a simpler translation of his definitions extracted from a paper he wrote and published way back on December 10th 1979. A working copy, as implemented by a website on the internet – can be found at SemsaBilge.com, a website dedicated to providing readers with kitchen faucet reviews. We love the implementation, and how this model has been implemented to showcase reviews.

Models

By model, we refer to knowledge hence it can either be an object or it can even be a structure or class of an object thus defining what several objects can do. A model should always have a one-to-one reference with its parts

Views

This is basically how the model is presented to the world. It would therefore require certain attributes of the model but not others and hence suppress them. Basically, the view is a presentation filter put on top of a model.

Naturally, a view goes on top of the model and gets whatever data it needs for its presentation from the model beneath by querying with it.

Controllers

A controller is what links the system and the user together. Thus it lets the user input certain parameters and accordingly provides an output using the views that in turn use a model beneath it all.

WTF Was All That?

Yes, what I just wrote all seems like abstract but this is the actual MVC concept and now to give some idea let’s bring it into the realm of web design with a typical website.

  • The Model – For a website it is all those functions and classes or objects that you have working to analyze data, retrieve data, add to the database, evaluate conditions and what not.
  • The View – The front of the website with which the user interacts thus the actual visual presentation that is always visible to the world.
  • The Controller – These are snippets of codes that exist on each code page that help it understand what the user wants and thus access the model code and do something with the data.

WordPress is an excellent example of the MVC design pattern. In fact, it is a solid MVC structure that is well compartmentalized and built for expansion in all areas. That is the allure of MVC – dividing up each major activity so that changes to one code does not really affect the other portion.

Here’s an excellent tutorial on the topic, for further reading.

Leave a Reply

Your email address will not be published. Required fields are marked *