Re: Existence of objects
Re: Existence of objects
- Subject: Re: Existence of objects
- From: YT <email@hidden>
- Date: Sun, 05 May 2013 22:24:03 -0700
Regarding "there must be a reference to objA stored somewhere" I kinda figured as much - BUT - was hoping there might be another way especially since there are those OO purists that condemn the use of any sort of "globalness".
What I have is a view within the main window that is a Quartz 2D graphical "thing" and I want to have a set of UI elements that a user interacts with to change the graphical presentation.
Well the UI elements are in the Delegate and the Graphical thing is in the view. The UI elements need to call methods in the view to change the graphical thing.
So from what I think I read in your post I have to "store" objA's ID in a common ancestor.
I'll have to ponder how to achieve that.
YT
On May 5, 2013, at 9:49 PM, Quincey Morris <email@hidden> wrote:
> On May 5, 2013, at 21:43 , YT <email@hidden> wrote:
>
>> In some thread an object is created with a set of methods.
>> Lets call this object objA.
>>
>> Later in time another objected is created perhaps in another thread (not sure if this note is relevant).
>> Lets call this object objB.
>>
>> Now objB needs to call a method in objA.
>>
>> Since objB came into being after objA how does objB detect that objA exists before attempting to call one of its methods?
>
> There's no magic here. If objB is to be aware of the existence of objA, there must be a reference to objA stored somewhere. (In fact, normally, there has to be a [strong] reference to objA store somewhere in order for objA to continue to exist. Otherwise, it's leaked or deallocated, depending on how you're handling memory management.)
>
> Usually, the reference to objA is held by some other object, whose existence is known to B. For example, most applications have an application delegate object that exists for the lifetime of the app, so this object could be designed to hold a reference to objA.
>
> If necessary, you can create a global variable to hold the reference to objA, but this would normally be done only if there were no context (that is, object graph) to which objA naturally belongs.
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden