On Jan 18, 2010, at 10:48, Jarod Wen wrote:

> Is it a proper design to use a NSDocument as a variable of another 
> NSDocument? 
> 
> I am now working on an application which generates some information from a 
> movie. The information generated will be showed as a table, and the 
> information in the table can be saved/opened. Multiple types of information 
> are possible so for one movie there may be several tables. 
> 
> I used the NSDocument architecture for the movie document, and I am a little 
> bit confused about the hierarchy now: is it possible to set the table as 
> NSDocument and use it as a variable as the movie document? i.e., if I use 
> MovieDocument for the movie and TableDocument for the table, it is ok to use 
> a TableDocument object as a variable of the MovieDocument? Or any better 
> pattern for this?

The question isn't whether one document object can contain a reference to 
another document object. The question is what's supposed to happen later when 
the derived (table) document is re-opened.

If the table refers to information in the original (movie) document, you'll 
need to open the movie document too. That's feasible (though I'd be a little 
careful about making assumptions about recursion-safety in NSDocumentController 
methods), but require careful error handling -- what if one document file has 
moved or disappeared?

OTOH if you have to open both documents together anyway, it sounds like your 
table perhaps should be *in* the movie document (that is, its data model should 
be part of the movie document data model) and you should provide multiple 
window types on the movie document.

So that's the first question you should decide -- whether you really need 2 
documents, or whether you need 2 windows onto the same document.


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to