I’ve always thought I understood MVC, but lately, after reading a lot of Stack Overflow posts on the subject, I’ve discovered that the ways in which MVC frameworks do things are slightly different from one another. More specifically, in the way in which the view and model interact, there seems to be two schools of thought:
When the user interacts with the view, the view notifies the controller, and the controller in turn does something to the model. When the model changes, the model notifies the controller, which in turn updates the view.
The view subscribes to the model. When the model changes, the view seems to be notified directly that it needs to update itself.
So my question is: In Cocoa Touch (iOS), what is the best way to do MVC? I’m mainly coding for iOS these days and am interested in the best practice for this platform only. (I’m not interested in how ASP.NET, Rails, Backbone, etc. do things.)
It would be wonderful if some KVO example code could be provided. Thanks. =)
The view means presentation of the model in a particular format. The controller responds to the user input and performs interactions on the data model objects. The controller receives the input, optionally validates it and then passes the input to the model.
The Model is the part of MVC which implements the domain logic. In simple terms, this logic is used to handle the data passed between the database and the user interface (UI). The Model is known as domain object or domain entity. The domain objects are stored under the Models folder in ASP.NET.
MVC – short for Model-View-Controller – is Apple's preferred way of architecting apps for its platforms, and so it's the default approach used by most developers on Apple platforms. In MVC each piece of your code is one of three things: Models store your data, such as the names of products in a store.
The model-view-controller (MVC) design pattern specifies that an application consist of a data model, presentation information, and control information. The pattern requires that each of these be separated into different objects.
Apple advocates use of the first method, I believe.
It is the modified version of the standard MVC model (the second approach), where model and view are totally separated. Personally I think that it’s cleaner and more extensible.
I found that the best basic theory on the matter is taught in Stanford University by a very talented teacher named Paul Haggarty. I recommend looking this course up on iTunes U - there are 18 lectures in HD video and ppt files to learn from. Here is a link to the course website: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/
I remember that he goes through the MVC part of the material very quickly but thoroughly, making this matter very clear. Also, I would have to say that the #1 school of thought is the one I agree more with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With