Objective-C and MVC

It has been a long-time ambition of mine to develop for the great iOS and Mac OS X. Although I did have a rough idea of what I needed to pursue this goal, I have come to realise that I wasn’t paying much focus on actually achieving it. So for the past week or so, I have managed to take glance over the Objective-C language and the Cocoa framework - (which is what the Mac OS and iOS are built on). Having spent my summer learning object-oriented programming concepts with Python, I think I am better prepared now to begin learning how to program for these two operating systems. In addition to this, I thought it might be a good idea to share my adventures in learning Objective-C, Xcode and Cocoa in my blog.

Model-View-Controller Paradigm

In this post, I’m going to discuss the Model-View-Controller (MVC) paradigm. This is the design architecture that Apple encourages developers to follow in order to create good applications. The MVC pattern is not only used in Objective-C, but also found in many other languages.

The MVC design splits objects in your programs into three sections: the model, the view and the controller.

The model is kind of like the back-end of your program. The user does not see it. For example, this is where you might have code that does calculations.

If we say the model is the back-end of your program, then the view would be your front-end. This is the actual interface which the user can see and interact with. 

The controller is the ‘middle-man’ between the model and the view. The controller can present the model to the view and also present the view to the model.

Mvc

The image above shows how the modelview and controller communicate: 

  • The controller can always talks to the model and the view by sending messages through outlets.
  • The model and the view should never speak to each other directly.
  • The view can ‘blindly’ communicate to the controller via actions and targets. In other words, the view can make a request to communicate to the controller.
  • The model can also ’blindly’ communicate to the controller via actions and targets. In other words, the model can make a request to communicate to the controller.

This is my basic understanding of MVC. For a more detailed and deeper understanding I would recommend to you to watch the Stanford’s CS193P Lecture.

Posted via email via Adnan’s Blog | Comment »

  1. adnan-chowdhury posted this

Blog comments powered by Disqus