My work logs today-some experiences on Event Delegation

Source: Internet
Author: User

Statement: the example below is nothing new. Almost every Member heard about this example. The reason why I wrote it down is because it is my own experience, not what it sounds, not what it looks like. It doesn't mean anything. Thank you!

At noon today, I accidentally found a detail: ordering meals in the restaurant is similar to the event subscription mechanism under. net.
The actual situation is as follows: When you get there, you only need to tell the waiter what you want to eat and what you want to cook. After the payment is made, the waiter will give you a menu, you can go to the table and wait. When the cooking and food masters cook the food and food, then the waiter will send the food and food to you, then you can enjoy it.

While in. the event subscription mechanism in net is similar to the above: When you communicate with the waiter about ordering meals, it is equivalent to declaring and subscribing to an event; when the cook and food master cooked the food and told the waiter to cook the food, it is equivalent to triggering an event (the menu in the customer's hand is equivalent. A delegate under. net, the delegate (that is, the menu) will know that the customer has set the dishes), and the waiter's serving is equivalent to the event processing when the event is triggered. The result of triggering an event is that customers can enjoy their food. Under the. NET event mechanism, you can ignore many things and save a lot of effort to achieve good results. For example, how to cook a meal or how much salt is needed for cooking can be ignored. Therefore, I want to define more. Net events by myself. Of course, this still needs to be written by myself.CodeThat is, it is equivalent to cooking by yourself, however, when cooking at that time, you only need to consider cooking, but the two processes of eating and cooking, or the two implementation details are separated to make the logical structure clearer and easy to manipulate, the only drawback is the increase in the amount of code. But I prefer to write code to measure the pros and cons.

 

Haha... It is meaningless to have a little experience and write it as you go.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.