Re: Communication between objects
Re: Communication between objects
- Subject: Re: Communication between objects
- From: Ken Thomases <email@hidden>
- Date: Wed, 11 Feb 2009 10:01:58 -0600
On Feb 11, 2009, at 9:42 AM, Jason Wiggins wrote:
Now, I understand I need a pointer to the "other object", but I am
failing (in a BIG way) in understanding HOW to get it or create it.
myControllerObject has a pointer to it's children because it knows
about it because it created it.
But if modelObject1 doesn't know modelObject2 even exists, how can I
create a pointer to it? Where do I get this reference from?
Pseudo code...
@interface
ModelObject1 *modelObject1;
ModelObject2 *modelObject2;
@implementation
myControllerObject {
int one, two;
modelObject1 = [[ModelObject1 alloc] init]; // I now have object 1
modelObject2 = [[ModelObject2 alloc] init]; // I now have object 2
one = [modelObject1 doMethod]; // doMethod returns an int
two = [modelObject2 doMethod]; // doMethod returns an int
[modelObject1 setPartner:modelObject2];
where you have implemented a -setPartner: method on ModelObject1 which
receives a pointer to a partner object, retains it, and stores it in
an instance variable. Later, when the object needs to interact with
its partner, it uses the pointer it stored in its instance variable.
Of course, "partner" is just a property name I made up; it's not
special to the framework. Use whatever property name makes sense for
your design.
Cheers,
Ken
_______________________________________________
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