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
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 mails | Author | Date |
|---|---|---|
| JArod Wen | Jul 1, 20:07 | |
| Andy Lee | Jul 1, 20:36 | |
| JArod Wen | Jul 1, 21:01 | |
| Andy Lee | Jul 1, 21:18 |






Cocoa mail archive

