Re: Delegates -- WHAT is delegated?
Re: Delegates -- WHAT is delegated?
- Subject: Re: Delegates -- WHAT is delegated?
- From: William Squires <email@hidden>
- Date: Sat, 23 Dec 2006 09:38:15 -0600
Oops, sorry to Nat Lanza, accidentally replied this message to him. :)
On Dec 19, 2006, at 10:02 PM, Nat Lanza wrote:
Sam Colombo wrote:
The delegating object in an application is often an NSApplication,
NSWindow,
or NSView object. The delegate object itself is typically, but not
necessarily, an object, often a custom object, that controls some
part of
the application (that is, a coordinating controller object)."
But how can you tell (or specify) what methods of a class are
delegatable?
It sounds like you're expecting delegation to be a much more formal
and compiler-enforced thing than it actually is.
Really, it's just a design pattern.
Cocoa objects that support delegates tend to implement delegation
to mean "When certain events happen, check to see if the delegate
implements a specific method selector. If it does, perform that
selector on the delegate object to give it a chance to respond to
the event".
This sounds like a more complicated version of RB's event model,
wherein you can make a "New Event" in a class so that subclasses will
get that event (if they want to code it), or ignore it (by putting no
code in it) in which case it'll be available to any subclass of that
subclass. Is this similar?
Implementing a method in the delegate object does *not* mean that
the delegate's method will be called instead of the delegating
object's method. That's entirely under the control of the main
object -- if the implementation *chooses* to call the delegate, it
can. The delegate does not in any way override the main object's
methods.
The reason you're not finding absolute answers on what is and is
not delegatable is that there *are* no absolute answers. The
methods that a given class chooses to pass on to its delegate are
entirely up to that class. A class may require its delegate object
to implement a formal protocol containing the methods it wants to
delegate, but it doesn't have to -- it can just use informal
documentation-based protocols instead.
Similarly, you're unlikely to find delegate support in the more
abstract base classes like NSView and NSResponder, because they're
generally not instantiated on their own. They serve as bases to
inherit from, and they're too general to really benefit from
delegates -- for example, he behavior you'd want from a delegate in
an NSOutlineView is pretty different from what you'd want in an
NSTextField, even though they both inherit from NSResponder.
--nat
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40satx.rr.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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