A real world example of a delegate would be:
You have a Person A.
Now you ask Person A to do Task A.
If person A has a delegate for this it would ask its delegate (e.g. Person B) to perform Task A for it.
Delegates are quite useful. Since it often allows to customize the functionality of the class without the need to derive from it. The is especially useful if you only need to customize a very small set of methods. Cocoa uses lots of delegation.
You can also find more information of this in a book regarding Design Patterns or in wikipedia:
http://en.wikipedia.org/wi
Main Topics
Browse All Topics





by: Blackninja2007Posted on 2008-10-30 at 05:50:55ID: 22840220
In essence, a delegate is a type-safe object that points to another method (or possibly
multiple methods) in the application, which can be invoked at a later time. Specifically speaking,
a delegate type maintains three important pieces of information:
" The name of the method on which it makes calls
" The arguments (if any) of this method
" The return value (if any) of this method
Once a delegate has been created and provided the aforementioned information, it may dynamically
invoke the method(s) it points to at runtime.