"Plug-in framework Discovery series" Establishing a subscription publishing mechanism based on delegates

Source: Internet
Author: User

Some time ago, there was an idea if you want to put together something that you feel is interesting and easy to develop, build a framework that will make it easier to develop, but later, as more things become involved, it's more and more likely that it's not something a developer needs because it's too miscellaneous, yes, As a framework, or simple point of good, and later work is busy, it stalled. These days on business trip to Guangzhou, night to have nothing to do, then pick up a module to say that said.

Messenger

In peacetime development, data transfer, processing, etc. can be done through the event mechanism, but the event mechanism will introduce coupling, of course, this coupling is often reasonable, but there are some times this coupling is not what you need, too much reliance will make you confused, The introduction of Messenger is to remove this dependency, please look at the figure below.

Figure 1. One-way dependencies between classes

Figure 2. Bidirectional dependencies between classes

Figure 3. Dependencies after the introduction of Messenger

Messenger's concept from the MVVM Foundation project, after reading the project's source code, found that the messenger is a good mechanism, based on this mechanism and the actual design of their own messenger.

As the name implies, Messenger is here as the executor of the Act, whose duty is to subscribe to the Act of pre acceptance, to perform these actions when needed, i.e. publish.

Figure 4. Messenger class diagram

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.