[wellylug] Re: GNUStep
Phillip Hutchings
sitharus at gmail.com
Fri Feb 25 16:05:35 NZDT 2005
On Fri, 25 Feb 2005 15:56:15 +1300 (NZDT), David Antliff
<dave.antliff at paradise.net.nz> wrote:
>
> On Fri, 25 Feb 2005, Phillip Hutchings wrote:
> > Oh, and make use of delegates. Before you subclass, always check if
> > you can do it with delegates.
>
> Hi Phillip, nice reply :)
>
> The only reference to delegates I can find in the Objective-C docs is in
> the glossary:
>
> "An object that acts on behalf of another object."
>
> This is also called a Proxy (re. IPC) I think. However I can't quite work
> out how this relates to the decision of whether to subclass or not...
That's a fairly consise description. Basically a delegate is a method
in a class (normally your controller class - GNUStep won't work well
unless you use MVC) that implements some behaviour pattern for
another.
If you look at Apple's NSSavePanel class delegates
(http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSSavePanel.html#//apple_ref/doc/uid/20000309/3201)
then you can see that delegates are used to control things like sort
orders, which filenames are valid, which files to show, if the dialog
expands certain items, etc. You also get special notifications as a
delegate when things such as selections change in case you want to
handle selection changes specially. These are called before the user
sees anything so that the application can instruct the class to do
something else.
> Perhaps there's another term in the documentation that better matches
> 'delegate' ? The closest thing I can think of that matches your
> description is a Category?
No, a category is a method of adding methods in to an exisiting class.
Delegates are better when you don't have the implementation to hand,
so can't actually see the internal data structures of an object. If
you can do it with a delegate, don't subclass. In Cocoa, and I'd
imagine in GNUStep, subclassing should only be needed for very complex
behaviour changes.
--
Phillip Hutchings
http://www.sitharus.com/
sitharus at gmail.com / sitharus at sitharus.com
More information about the wellylug
mailing list