I understand delegates encapsulate method calls. However I'm having a hard time understanding their need. Why use delegates at all, what situations are they designed for?
Fear of failure can cause leaders to hold on to work and refuse to delegate. They feel that they need to take charge and deliver the work personally to make sure it is done to the right standard. Some leaders like to say: “If you want something done properly, do it yourself.”
A delegate is a person selected to represent a group of people in some political assembly of the United States.
Other reasons why managers do not delegate as much as they could include: The belief that employees cannot do the job as well as the manager can. The belief that it takes less time to do the work than it takes to delegate the responsibility. Lack of trust in employees' motivation and commitment to quality.
Benefits of Delegating Delegation of tasks to others offers the following benefits: Gives you the time and ability to focus on higher-level tasks. Gives others the ability to learn and develop new skills. Develops trust between workers and improves communication. Improves efficiency, productivity, and time management.
A delegate is basically a method pointer. A delegate let us create a reference variable, but instead of referring to an instance of a class, it refers to a method inside the class. It refers any method that has a return type and has same parameters as specified by that delegate. It's a very very useful aspect of event. For thorough reading I would suggest you to read the topic in Head First C# (by Andrew Stellman and Jennifer Greene). It beautifully explains the delegate topic as well as most concepts in .NET.
Well, some common uses:
Don't think of them as encapsulating method calls. Think of them as encapsulating some arbitrary bit of behaviour/logic with a particular signature. The "method" part is somewhat irrelevant.
Another way of thinking of a delegate type is as a single-method interface. A good example of this is the IComparer<T>
interface and its dual, the Comparison<T>
delegate type. They represent the same basic idea; sometimes it's easier to express this as a delegate, and other times an interface makes life easier. (You can easily write code to convert between the two, of course.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With