Great - another perfectly good term hijacked and hosed
A [link|http://www.stepwise.com/Articles/Technical/2000-03-03.01.html|delegate] in Cocoa (Objective C) is something like this:
\n@interface NSApplication // system class\n{\n id _delegate;\n ...\n}\n-setDelegate: d;\n-(void)quit;\n\n@end\n\n\n@interface MyApplicationDelegate\n\n-(BOOL)applicationShouldQuit: sender;\n//-(void)applicationWillQuit: sender; // not implemented\n\n@end\n\n@implementation NSApplication\n\n-quit\n{\n // this isn't exactly how its done but you get the idea\n if([_delegate respondsToSelector: @selector(applicationShouldQuit:)] &&\n [_delegate applicationShouldQuit: self])\n {\n if([_delegate respondsToSelector: @selector(applicationWillQuit:)])\n {\n [_delegate applicationWillQuit: self];\n // proceed with quitting\n }\n }\n}\n\n@end\n
Its a way of adding additional behavior to an object by delegating key behavior to another object. Its used all through the Cocoa apis and its really useful since you just implement the methods to get the notifications you care about in your delegate - no subclassing required most of the time.
Somehow, I doubt this is what C# means by delegation.
Edit - inserted pre tags
Great - another perfectly good term hijacked and hosed
A delegate in Cocoa (Objective C) is something like this:
@interface NSApplication // system class
{
id _delegate;
...
}
-setDelegate: d;
-(void)quit;
@end
@interface MyApplicationDelegate
-(BOOL)applicationShouldQuit: sender;
//-(void)applicationWillQuit: sender; // not implemented
@end
@implementation NSApplication
-quit
{
// this isn't exactly how its done but you get the idea
if([_delegate respondsToSelector: @selector(applicationShouldQuit:)] &&
[_delegate applicationShouldQuit: self])
{
if([_delegate respondsToSelector: @selector(applicationWillQuit:)])
{
[_delegate applicationWillQuit: self];
// proceed with quitting
}
}
}
@end
Its a way of adding additional behavior to an object by delegating key behavior to another object. Its used all through the Cocoa apis and its really useful since you just implement the methods to get the notifications you care about in your delegate - no subclassing required most of the time.
Somehow, I doubt this is what C# means by delegation.
"Whenever you find you are on the side of the majority, it is time to pause and reflect" --Mark Twain
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." --Albert Einstein
"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses." --George W. Bush