Java and C # event handling mechanisms

Source: Internet
Author: User
When learning a language, if there is no good understanding of its event handling mechanism, it is not well. I've been learning Java and C # for some time. In their plethora of similarities and even similarities, a very different event-handling mechanism suddenly occurs. So I want to share my opinion with you.
The object-oriented mechanism is taken in Java. The function callback mechanism in C/C + + is followed by a.
In Java, to implement custom event handling, you must go through the following steps:
1 Develop custom event classes.
2 defines the listener interface.
3 defines the interface of the event-excited person.
public void add listener (listener);
public void Remove listener (listener);
protected void Process Event (event);
4 to implement the event-excited person.
5 realizes listening to this interface.
And in C #:
1 Define an event agent:
2 defining events;
3 event handler function.

The event mechanism in Java is well understood. When an event fires, the process event method is invoked. This event method executes all listeners one at a time and it listens to the interface of the event. (If the message is not consumed, allow delivery.) Of course, this is not necessary, because the process method is written by itself, you can determine the action it performs.

In C # It simplifies the work of writing process event methods yourself. However, it is difficult to understand the event processing mechanism, and I look quite marvellous. is actually the callback mechanism in C + +. Its approach is to hook up the listener function on the event agent chain. When an event is triggered, the functions on the event agent chain are executed sequentially. (If the message is not consumed, allow delivery.) )
adjourned


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.