discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: objective-c: how slow ?


From: Richard Frith-Macdonald
Subject: Re: objective-c: how slow ?
Date: Fri, 7 Sep 2001 22:03:00 +0000

On Saturday, September 8, 2001, at 01:36 AM, Marko Mikulicic wrote:

[snip]
Objc has a simpler lookup because it doesn't have multiple inheritance,
delegation
Doesn't forwarding and DO count as delegation?

Not really. Delegation uses the delegate to lookup the method
but forwards the original receiver.
(One example is better than a thousand words. see attachment)

Actually, what you are describing is not true delegation ...
Delegation is what is commonly done in ObjC - an object asks another
object to do a job for it.

The capability you are describing here is also possible using the
ObjC runtime (the GNUstep base library uses it in a few places), and
is called 'behaviors'.   The object takes on a behavior of another
object rather than delegating  to another object.

So, with delegation and object A which does not handle a particular
message, passes the message to a delegate object B which executes
the appropriate method, whereas with behaviors, A gets the method from
B and executes it itsself.

The behavior mechanism is not directly supported by the language, and
is therefore dangerous in ObjC - since you need to be careful not to
take on any behavior which would try to work with instance variables
that don't exist in your object and cause a crash.  In other languages
where ivars are only accessed by methods, you just need to worry about
runtime exceptions, not actual crashes when you make a mistake.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]