Skip navigation.
 
mlRe: How to make the FileOwner of a nib file accessible globally in whole project (was Re: Cocoa-dev Digest, Vol 5, Issue 1168)
FROM : Andy Lee
DATE : Tue Jul 01 21:18:29 2008

On Jul 1, 2008, at 3:01 PM, JArod Wen wrote:
> A way I can find from my head is setting the instant variable in 
> other classes... So all the related classes should have one instant 
> variable like
>
> MovieDocument *movieDocument;
>
> And also the getter and setter. Is there any other way for this 
> purpose?


This sounds right for you.

When one object X is supposed to know about another object Y, using an 
instance variable is generally the right approach.

If there is only one instance of Y in the whole program, sometimes a 
global variable is a reasonable approach, or a singleton instance that 
can be retrieved by a class method.  But this is usually not the right 
approach for objects that are treated as documents, because an 
application can usually open multiple documents.

There are other ways objects can know about each other, like KVO and 
bindings.  Sometimes X doesn't need to know about Y all the time, only 
when certain messages are sent, in which case Y can be passed as an 
argument in the message.

But the most natural approach in most cases is an instance variable.

I don't know much about using NSDocument, so if you have questions 
about that perhaps others can help.

--Andy

Related mailsAuthorDate
mlRe: Cocoa-dev Digest, Vol 5, Issue 1168 JArod Wen Jul 1, 20:07
mlHow to make the FileOwner of a nib file accessible globally in whole project (was Re: Cocoa-dev Digest, Vol 5, Issue 1168) Andy Lee Jul 1, 20:36
mlRe: How to make the FileOwner of a nib file accessible globally in whole project (was Re: Cocoa-dev Digest, Vol 5, Issue 1168) JArod Wen Jul 1, 21:01
mlRe: How to make the FileOwner of a nib file accessible globally in whole project (was Re: Cocoa-dev Digest, Vol 5, Issue 1168) Andy Lee Jul 1, 21:18