Design Mode-policy Mode

Source: Internet
Author: User

I heard that the IOT college is about to organize activities recently. Electronic, electrical, and physical have prepared a program. However, due to the limited schedule of the program, only one professional student can perform the program.

The host finds four groups and determines which group performs on stage.

Standard 1: hard work. The rehearsal of electrical appliances is very hard. Let them participate.

As a result, the host wrote an electrical performance during the performance process.

Standard 2: performance. Electronic performances are the most exciting. The host again passed the electric appliance and wrote the electronic information in the performance process.

However, there is a standard three ....... No dispute...

The host said it was too troublesome to change it.

In this case, I have another secret. You decided to submit the information of each group and the final selection criteria to my secret. Let my secret tell me the final result.

The rule mode is described here. I don't know if such a metaphor is inappropriate.

Here, three professional performances are specific strategies. The performance process includes performers and professionals. It is an abstract strategy. The secret decides which group is on stage based on the information of each group assigned to her and the selection criteria. It is the context. The host is the client. The host can obtain the answer based on the information provided by the secret and does not need to take part in the specific screening.

Let's take a look at the structure of the above policy pattern.

Policy mode analysis:

Policy mode is a method that defines a series of algorithms. In terms of concept, all these algorithms perform the same job, but implement different ones. They can call all algorithms in the same way, reduces the coupling between various algorithm classes and algorithm classes. DPE ].


The strategy class layer of the Policy mode defines some reusable algorithms or actions for columns for the Context. Inheritance helps to analyze the common functions of these algorithms. [DP]

In addition, the unit test is simplified, because each algorithm has its own class, you can test the DPE independently through its own interface]

Related Article

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: 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.