[Golang] Task flow processing thinking based on Golang interface feature derivation

Source: Internet
Author: User

In many of the application scenarios of the design program we encounter task flows that are broadly divided into three phases.

First, entrance

One or more entrances, waiting for blocking, or unsolicited requests.

==============================

For example, the task flow needs to accept application requests from HTTP and FTP, and subsequent requests for acceptance may be added in other ways.

Second, processing

Multiple portals can correspond to one handler or multiple handlers.

==================================

For example, HTTP and FTP Multiple entry procedures need to correspond to one or more processing logic, also faced with the increase of the processing program extensibility.

Third, export

Multiple handlers or one handler for multiple exits or one exit.

==================================

such as alarm mode has mail alarm, alarm and so on, the following may increase SMS alarm and so on.

In fact, the vast majority of demand can be abstracted into the above thinking.

So the extensibility requirement for this kind of problem is to change a small amount of the original code or simply not change the original code when expanding the function. Regardless of the software refactoring level, when the new recruits take over the boss's code, I think the most headache is to increase demand, because you do not know what to change the code to bring a hidden BUG.

We always ideal can use the "plug-in" thinking to adapt to demand, write a good framework, and then classify, each of the abstract role is a large container, and then each time to the container plug into a plug-in, to a demand, do a plug-in. To two needs, do two plug-ins to plug in a pair.

More "excessive" requirements are inserted into the plug-in must have a button to control whether to enable the plug-in, the reason is to plug the plug-in too time-consuming (corresponding code in the comments N multiple lines).

In short, everything we want the effect is that each plug-in independent work, non-corresponding, increase the scalability. The disadvantage is that there may be a part of the redundant code, but this is more than the handover to work so that people every day behind the black you have to be strong.

First we use the Golang to create a demand container.

[Golang] Task flow processing thinking based on Golang interface feature derivation

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.