Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios networking code in the model?

I recently watched the 'Network Apps for the iPhone OS' videos for WWDC 2010 in iTunes U and the speaker said that the best place to write your networking code is in the model. This kind of confused me because I have always placed this code in the controller classes. Can someone please explain why this is the best place for the networking code? Also if possible please provide an example, code or pseudocode, either works.

like image 969
marchinram Avatar asked Dec 06 '10 10:12

marchinram


1 Answers

I wonder if we're all using the same terminology? Here's what I would use and I think (though I'm saying this without much context) what the WWDC presenter meant:

  • Model. The data
  • View. What it looks like in the UI
  • Controller. The layer than mediates between the Model and the View

Using these definitions, the controller is a terrible place to keep any networking code. It has nothing to do with the interaction between the UI and the data.

Of course there's no reason why you couldn't have multiple classes for your model: one for the data representation and another to mediate between your web service and your data model. In this sense it would be a controller but would, nevertheless, be in the model layer of the application.

like image 119
Stephen Darlington Avatar answered Sep 18 '22 15:09

Stephen Darlington