• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Delegates -- WHAT is delegated?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Delegates -- WHAT is delegated?
      • From: William Squires <email@hidden>
    • Re: Delegates -- WHAT is delegated?
      • From: Sam Colombo <email@hidden>
    • Re: Delegates -- WHAT is delegated?
      • From: Hal Mueller <email@hidden>
References: 
 >Re: Delegates -- WHAT is delegated? (From: Sam Colombo <email@hidden>)

  • Prev by Date: Re: Delegates -- WHAT is delegated?
  • Next by Date: Re: Delegates -- WHAT is delegated?
  • Previous by thread: Re: Delegates -- WHAT is delegated?
  • Next by thread: Re: Delegates -- WHAT is delegated?
  • Index(es):
    • Date
    • Thread