Involved Event development Application delegation

Source: Internet
Author: User

Yesterday, Insus.net wrote an article "ASP." NET is simple and object-oriented development "http://www.cnblogs.com/insus/p/4146503.html. At that time the idea, can only so the level, the Netizen said should be uses the state design pattern, but insus.net thought this case did not use to the state design pattern.

On the contrary, I think the switch has two events, that is, open and close. The following insus.net decided to refactor the switch class, using a delegate instead.

A common power switch, let us do what, what to do, although it has built-in features to achieve, normal should also have external functions.

In the previous article, the properties are closed to get the output parameters, after using the event delegate, the two events on and off to get the parameters.


So create a Runeventargs class that inherits the EventArgs base class.

Ok, now we're going to refactor the switch class:

Remove the useless code with the red line, and add the tags 1 to 3 section code, respectively. Mark 1 is the declaration of the street to a commissioned delegate and two event events. Tag 2 and tag 3 respectively in two event outgoing parameters.


Next refactor the Default2.aspx.cs, you need to implement two events in the switch class here:



In implementing two events, get the parameters of the switch output:

In this refactoring, we learned to use delegates, E to pass parameters. The responsibility is to distinguish between a property is an event.


The following are the ASP. NET events related to delegates:
User Control (UserControl) Usage Events http://www.cnblogs.com/insus/archive/2011/11/16/2251314.html
"Event Interface" http://www.cnblogs.com/insus/archive/2011/12/12/2284382.html
Web page (aspx) and user control (ascx) interaction and logic processing http://www.cnblogs.com/insus/archive/2013/03/09/2951161.html
Interaction between the observer pattern and the user control http://www.cnblogs.com/insus/archive/2011/12/10/2283142.html

Involved Event development Application delegation

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.