Re: Delegates -- WHAT is delegated?
Re: Delegates -- WHAT is delegated?
- Subject: Re: Delegates -- WHAT is delegated?
- From: Nat Lanza <email@hidden>
- Date: Tue, 19 Dec 2006 23:02:36 -0500
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".
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:
This email sent to email@hidden