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