Re: Existence of objects
Re: Existence of objects
- Subject: Re: Existence of objects
- From: Quincey Morris <email@hidden>
- Date: Sun, 05 May 2013 21:49:43 -0700
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