Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Delegate explanation
Message
From
25/04/2002 13:13:11
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00649150
Message ID:
00649207
Views:
8
>I was hoping someone here could give me a good explanation of delegates and why I want to use them.

Delegates to me seem like a way to avoid basic OOP principles. For example, as a VFP developer, I would write something like this:
define class transfer as custom

function sendfile

* Process the file here

* Pass the sending of the file to an abstract method
this.TransferFile()
return

protected function TransferFile
* Abstract method
return

enddefine
Then, depending on what server I was using, I'd create a subclass to implement the transferfile:
define class ftptransfer as transfer

protected function TransferFile
* Actually do the FTP transfer here
return

enddefine
I coudl write a subclass for a File, HTTP, or SOAP transfer too.

With delegates on the other hand, you don't need to do anything like that. Your client code can create a transfer object, and an ftp object. It can then create a delegate based on the instance of the ftp object, and send THAT to the transfer object. The transfer object can then execute the delegate, which will do an FTP transfer, even though it has no idea how the delegate was created or what it even will do.

Knowing this, it also plays a major role in .NET's event handler. For example, throughh the use of delegates, your client code says that when a sales order is created, it can call methods (which will be the event hanlders) of whatever objects subscibe to that event. The way it knows what methods to call is dictated through delegates.

Does that help?
Previous
Reply
Map
View

Click here to load this message in the networking platform