This is a discussion on What is a delegate method? within the Microsoft .NET forums, part of the Programming Talk category; see this code: Code: delegate decimal CalculateBonus(decimal sales); Anyone can tell me what does it mean? Thank in advance...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Tells you that you can create your own function to calculate some bonus that takes and returns decimal. Then you provide the address of that function to the class that exposes the delegate declaration. When you use that class and the class needs to calculate bonuses it will call your function.
|
|
|||
|
Thank you very much. After some lessons, i've known about delegate right now. But i still dont know clearly how and when we use delegate, and advantages and disadvantages in using this method?
__________________
Think about bigger things |
|
|||
|
let's say you are creating a general component that would track sales and salesman. You want to give your client - a programmer who bought your component - some freedom about how the bonus for a salesman is calculated.
so, you expose the delegate CalculateBonus. Your client writes his own (c#) procedure decimal YukataBonus( decimal sales ) { if( sales < 50000.0 ) { return 0.0; } else if( sales < 550000.0 ) { return (sales - 50000.0)*0.1; } return 100000.0; } now your component will get the address of YukataBonus function and it will call it every time it needs to calculate bonus. This way your code cooperates with the code from your user without you giving him any source code. |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Best Practices for Checking Prerequisites | Mario T. Lanza | Software Patterns | 2 | 09-01-2004 06:51 PM |
| Objective-C FAQ | stes@pandora.be | Tech FAQ | 0 | 06-18-2004 02:58 PM |
| Objective-C FAQ | stes@pandora.be | Tech FAQ | 0 | 05-18-2004 02:59 PM |
| Smalltalk FAQ (v.1.0) | Vikas Malik | Tech FAQ | 0 | 04-17-2004 08:27 AM |
| Objective-C FAQ | stes@pandora.be | Tech FAQ | 0 | 04-16-2004 02:51 PM |