View Single Post
Old 03-03-2004, 11:38 AM   #2 (permalink)
ender
Code Monkey
 
ender's Avatar
 
Join Date: Mar 2003
Location: Evansville, IN
Posts: 75
ender is on a distinguished road
Send a message via AIM to ender Send a message via Yahoo to ender
Delegates....

Here is my two bits to your question. Delegates (as I understand them) are just a typesafe way of passing pointers to member-functions/or functions in a type-safe way. Previously (in C++ and such) we just had a memory address, and we could call it with anything, which might not be what the function wants. Also, it doesn't hold any state information about the function. Delegates make it a type-safe way to call member functions.

A real world example besides an event handler would be anywhere you have used pointers to functions. For instance, I used them in a MUD I did for CS290 to handle how certain commands are processed. (Not 'events' but probably more like it than you wanted). For instance, someone typed "GO WEST" and I passed WEST to the function that was pointed to by the map of strings to functions. In this case, the function 'GO'. However, because of the uniformity of the arguments (I didn't pass any integers or anything) there wasn't any problems making sure there were sufficient arguments or types the the function because it was all standardized.

Another example of where you would use these are for dynamic validation of data. For instance, someone passes you a phone number, and depending on where you are located, or selected country, you can customize the function that will handle that phone number to validate it.

This is what I think, if I am wrong about what delegates are, please ignore/correct my post!

Hope this helps,
Ted Morse
__________________
while(1) fork();
ender is offline   Reply With Quote