Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What Is A Delegate?
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01028422
Message ID:
01028444
Views:
19
While it is not quite the same thing and each language/approach has its own advantages and disadvantages... in VFP you can send an object in as a parameter or send in a string variable and use Evaluate() or & Macro Substitution on it to achieve essentially the same thing (speaking of this particular aspect of Delegates only here).

>Actually, when you said 'pass around an object that essentially represents a
>method/function', that said it all. Wish I could do that in VFP.
>
>
>
>>OK, there is a couple of things that make delegates worthwhile... asynchronous method calls and being able to pass the method around as an object. Granted, the example below and from the link I gave is somewhat poor. Good examples are sometimes hard to come by, I mean when OOP first started becoming the rage I thought I would puke if I had to go through one more example where they used a Car for the example. So don't get hung up on that example and think about the power of being able to pass around an object that essentially represents a method/function. ValidateCustomer doesn't need to know anything about NotifyClient in order to function, it doesn't even need to know it's name, it just knows that the signature of the function calls for a string. If you were to have called NotifyClient directly then you've broken this encapsulation. As it is now it doesn't matter what method it is... it could be anything as long as it accepts a string (in this case a phone number). It may take
>>some time before the true power of this type of design sinks in, but it is very scalable and maintainable.
>>
>>>Ok, I read the article, and I understand it.
>>>
>>>Here is the code from the article
>>>
>>>
>>>Public Delegate Sub MakeDelegate (ByVal PhoneNo As String)
>>>
>>>Public Class Customer
>>>
>>>    Public FirstName As String
>>>    Public LastName As String
>>>
>>>    Public Sub ValidateCustomer (ByVal objDelegate As MakeDelegate, _
>>>                                ByVal PhoneNo As String)
>>>        If PhoneNo.StartsWith ("479") Then
>>>            objDelegate.Invoke(PhoneNo)
>>>        End If
>>>    End Sub
>>>
>>>End Class
>>>
>>>Dim objCustomer As Customer = New Customer()
>>>
>>>Dim objDelegate As MakeDelegate
>>>objDelegate = AddressOf NotifyClient
>>>
>>>objCustomer.FirstName = txtFirstName.Text
>>>objCustomer.LastName = txtLastName.Text
>>>
>>>objCustomer.ValidateCustomer(objDelegate, txtPhoneNo.Text)
>>>
>>>
>>>Private Sub NotifyClient(ByVal PhoneNo As String)
>>>  MsgBox("This Customer is Eligible for 10% Discount")
>>>End Sub
>>>
>>>
>>>
>>>In the method ValidateCustomer, why create and use a delegate?
>>>Why not just call the NotifyClient method instead?
>>>
>>>
>>>Thanks
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>>This may help you out...
>>>>
>>>>http://www.15seconds.com/issue/020815.htm
>>>>
>>>>>I need a clearer understanding of Delegates. Can someone
>>>>>break it down for me?
>>>>>
>>>>>Thanks
>>>>>
>>>>>K
Previous
Reply
Map
View

Click here to load this message in the networking platform