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

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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