Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delegate explanation
Message
De
25/04/2002 13:13:11
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00649150
Message ID:
00649207
Vues:
9
>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?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform