Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Apple say iPhone apps use MVC?

Apple describes the architectural pattern used by iPhone apps as MVC. However, virtually no modern application uses MVC (as described by Trygve Reenskaug). Modern operating systems, including iPhone OS, inherently handle controller responsibilities. What is mistakenly and commonly referred to as MVC is actually MVP.

Why does Apple say MVC and not MVP?

like image 218
4thSpace Avatar asked Nov 27 '22 23:11

4thSpace


2 Answers

This is certainly a good question - and it's one I'm not sure I know the answer to. I think Apple uses the term MVC almost universally because many of the views in Cocoa/AppKit use data bindings to draw data directly from the model and this breaks with the MVP pattern. In the diagram below (from This article), the MVP model shows all the data moving through the presenter - and this generally isn't the case for well-built Cocoa apps.

In most Cocoa apps, data bindings and key-value observation are used to bind the view and model together without requiring the interaction of the controller to update them. Also, in Cocoa apps there is a primary controller which determines when and where views are loaded. To borrow from glenn_block's response to this question:

In the MVC, the Controller is responsible for determining which View is displayed in response to any action including when the application loads. This differs from MVP where actions route through the View to the Presenter.

alt text
(source: vuscode.com)

Hope that helps! It could be a totally random decision on Apple's part - but I think their choice is reasonable.

like image 69
Ben Gotow Avatar answered Dec 09 '22 16:12

Ben Gotow


In most Cocoa apps, data bindings and key-value observation are used to bind the view and model together without requiring the interaction of the controller to update them. Blockquote

I disagree.

According to Paul Hegarty, Stanford professor of the course CS193P (Programming on iOS7), the Model in Cocoa never talks to the View. I have watched all the courses (2011, 2012, 2013, they are all freely available on iTunesU), and every time he repeat this. In the fall 2013 course he makes the example of a list of songs (your model) that you may want to display in your iPhone (as view): the view ask the controller a bunch of songs to display, and it's the duty of the controller to talk to the model, take some songs, and push them to the view. The view will only display songs. The view never holds model data.

He says that the KVO (key value observing) is a patter for the communication between Model and Controller. There is no binding.

I think "Apple MVC" == "Microsoft MVP".

"Microsoft MVC" is only for the web, and is called "ASP.NET MVC 4". In the web, the Controller is the "user input entry point", while in the desktop/touch is the View

like image 37
Yagami Light Avatar answered Dec 09 '22 16:12

Yagami Light