开发者

A question about dependence and MVC on Cocoa

I'm a newbie in Cocoa developer, beside this I know well a lot of patterns. So far until now I understand that MVC have in mind avoid dependences between model, view and control. Well, I gave a look in some examples of controller and I found a behavior开发者_Go百科 that apparently do not agree with that goal. Normally, in theses examples, I found a controller creating a instance of model, in other words, the controller is explicitly dependent of the model. For me a solution could be the use of factory pattern to avoid dependence between controller and model.

What you think about it? How you solve that problem?


In Cocoa, the controller's role is to mediate between the model and the view. There should be a wall between model and view, so you can swap out either one without the other noticing; the controller straddles this wall, and so knows about both.

So, yes, controllers generally do know about both the model and the view. In the Cocoa world, this is normal.

I have never found a good use for “dependency injection” (a.k.a. hiding controller code in model/view code files) or the factory pattern (objects that exist solely to make other objects). Classes should be self-contained; categories to extend them should be rare. And classes, at least in Cocoa, should be capable of making their own instances.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜