Skip navigation.
 
mlRe: General MVC and ownership question
FROM : Jens Alfke
DATE : Tue Mar 04 18:05:38 2008

On 3 Mar '08, at 6:16 PM, Graham wrote:

> The question is: would the better design be one-controller-per-view, 
> or a single controller supporting multiple views? In other words 
> should the controller typically associate with a single view or the 
> data model?


Generally there should be a controller per view. This is because the 
controller directly operates on the objects in the view (it has 
IBOutlets, in Cocoa terms), and because you might have different kinds 
of views (like list vs. icon) that require entirely different 
controller implementations.

> The follow-on question would then be: what would be considered the 
> optimal "ownership" relationships between the various objects in the 
> system? Do data models typically own their controllers, or should 
> the controller(s) own the data model?


There's usually a central "document" object that owns the controllers, 
which in turn own the views. You can think of the document as an über-
controller.

Cocoa supports this model via the NSDocument and NSWindowController 
(and now NSViewController) classes.

Have you considered using GC? I'd recommend it, if your app doesn't 
have to support 10.4, and if it doesn't depend on 3rd party Cocoa 
libraries that aren't GC-ready. It makes this stuff so much easier.

—Jens

Related mailsAuthorDate
mlGeneral MVC and ownership question Graham Mar 4, 03:16
mlRe: General MVC and ownership question Jens Alfke Mar 4, 18:05
mlRe: General MVC and ownership question Graham Mar 4, 23:59