开发者

Where does NSURLConnection belong in MVC?

Where does NSURLConnection a开发者_如何学编程nd it's delegate methods belong in MVC? I think it is Model? But should not model be dumb and not know any thing about connections ? but putting in controller also does not make sense?


IMHO NSURLConnection is model. The connection part is not about model, but about data management that model is actually responsible for.


The answer is in the delegate design pattern.

If your query is fired by UI actions, then the constructor, configuration, and firing of the thing is in the controller. As a "connective" action, it's appropriate for that to be a controller-level function.

If what it updates is underlying model stuff, set up its delegate to point to the model class, and do the data receiving, parsing, and model updating there. The model can then be ignorant about everything but data-related issues.

This is a case where the fundamental design patterns of Cocoa Touch really lend themselves to MVC-style separation of concerns.

(Also you'll be happier learning about ASIHTTPRequest, rather than continuing to use NSURLConnection, but that's not the question you're asking.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜