What is Model-View-Controller?

At first for me this concept was a bit hard to grasp, hopefully i can break it down to basics here.

The Model-View-Controller is basically a design theory and a very logical organization of the parts or an iPhone application.

Model is basically the classes that hold your application’s data. For example if you created an application that when a button was pressed would take the name of that button (a string) then output that string to a label or a text field, then in this instance the Model object would be the string itself, the actual data that was used and transferred. This is a very loose example actually but, its simplicity I think makes the Model object more understandable. Most application that use a Model object will be storing or preserving data like when using Core Data classes.

View is fairly easy, if you can see it then its place in the MVC theory is View.  Although in some application there is a necessity for View objects to be hidden or invisible, these are still considered to be View objects. A view object can be windows, buttons, labels, etc…

Controller is the mediator between the Model and View. A controller object interprets user actions made in view objects and communicates new or changed data to the model layer. When model objects change, a controller object communicates that new model data to the view objects so that they can display it. Simply, the Controller object looks at changes from either the Model or View and Tell them how to behave.

The main reason for MVC theory is very similar to Object Oriented theory, where any object that is written should be easily identifiable as belonging to one of these three categories and no functionality within that object could be classified as belonging to any of the other two categories. Its all about abstraction and portability! An object that implements a button (View) should contain code that processes data (Controller) when it is tapped.  A class that implements a button can be used in any application but, a class that implements a button that processes a specific action or calculation can only be used in that one particular application.

This entry was posted in iPhone Development. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">