Re: Events between Objective C objects
Re: Events between Objective C objects
- Subject: Re: Events between Objective C objects
- From: Tom Sutcliffe <email@hidden>
- Date: Tue, 20 May 2003 00:04:57 +0100
Can't you just use the java implementations of Notifications? They're
not as elegant as in Obj-C but still not too bad
NSNotificationCenter.defaultCenter().addObserver(anObject, theSelector,
"NotificationName", someObject)
if you have some legacy eventListener code you'll just have to call a
dummy method with theSelector which then calls the eventlistener. I've
found that generally Notifications are the easiest part of using the
java bridge, particularly since the objects of the notifications are
automatically bridged both from ObjC to Java and Java to ObjC.
Regards,
Tom
On Monday, May 19, 2003, at 11:14 pm, Rolf wrote:
I have tried using NSNotification now. It's working nicely, and seems
to be exactly what I'm looking for. I was under the impression that
Notifications were broadcast and thus had a performance penalty, but
as you point out objects register for the notifications they are
interested in = exactly
what I need. Thanks! The next challenging thing I need to do is to use
this over the Java bridge (ie Objective C NSNotification <-> Java
EventObject/EventListener). That will probably be a tough one, but
then what's life without challenges :-)
/Rolf
20.05.2003 00:07:50, skrev "Jonathan E. Jackel" <email@hidden>:
Here's an example from Delphi (that I have more experience with)
which illustrates what I'm searching for in Objective C:
object1.OnSomeConditionOccured := object2.theConditionHasOccured.
After this line of code has been run, object1 will,
(asynchronously - when the condition occurs), call instance
method theConditionHasOccured of object2. The two classes of
object2 and object1 do not need to anything about each other,
just the definition of the event object. The event
object can be customised and contain any number and mix of
parameters. To close the "connection" one would issue:
object1.OnSomeConditionOccured := nil;
Clark: I will look into NSNotifications. I was assuming that
there would be some performance penalty in using broadcasting
instead of a one-to-one type connection. But if that isn't the
case then I guess NSNotifications will do.
Now it sounds like you want notifications. I must have misunderstood
your
first message.
Notifications are not broadcast. Objects register for the
notifications
they are interested in. When those notifications come in to the
notification center, they are forwarded to the objects that
registered. The
penalty is simply one extra message sent to the notification center.
Try it. See if it works well enough. If it's not good enough,
optimize
later.
Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.